📌  相关文章
📜  Java中的 CompositeName isEmpty() 方法和示例

📅  最后修改于: 2022-05-13 01:55:36.847000             🧑  作者: Mango

Java中的 CompositeName isEmpty() 方法和示例

javax.naming.CompositeName 类isEmpty()方法用于检查此复合名称对象是否为空。如果复合名称的组成部分为零,则称复合名称为空。

句法:

public boolean isEmpty()

参数:此方法不接受任何内容。

返回值:如果此复合名称为空,则此方法返回 true,否则返回 false。

下面的程序说明了 CompositeName.isEmpty() 方法:
方案一:

// Java program to demonstrate
// CompositeName.isEmpty()
  
import java.util.Properties;
import javax.naming.CompositeName;
import javax.naming.InvalidNameException;
  
public class GFG {
    public static void main(String[] args)
        throws InvalidNameException
    {
  
        // create composite name object
        CompositeName CompositeName1
            = new CompositeName("a/b/z/y/x");
  
        // apply isEmpty()
        boolean isEmpty
            = CompositeName1.isEmpty();
  
        // print value
        System.out.println(
            "This composite "
            + "object is empty: " + isEmpty);
    }
}
输出:
This composite object is empty: false

方案二:

// Java program to demonstrate
// CompositeName.isEmpty() method
  
import java.util.Properties;
import javax.naming.CompositeName;
import javax.naming.InvalidNameException;
  
public class GFG {
  
    public static void main(String[] args)
        throws InvalidNameException
    {
  
        // create composite name object
        CompositeName CompositeName1
            = new CompositeName("");
  
        // apply isEmpty()
        boolean isEmpty
            = CompositeName1.isEmpty();
  
        // print value
        System.out.println(
            "This composite "
            + "object is empty: "
            + isEmpty);
    }
}
输出:
This composite object is empty: true

参考资料:https://docs.oracle.com/javase/10/docs/api/javax/naming/CompositeName.html#isEmpty()