Java中的 CompoundName isEmpty() 方法和示例
javax.naming.CompoundName 类的isEmpty()方法用于检查此复合名称对象是否为空。如果复合名称的组成部分为零,则称该复合名称为空。
句法:
public boolean isEmpty()
参数:此方法不接受任何内容。
返回值:如果此复合名称为空,则此方法返回 true,否则返回 false。
下面的程序说明了 CompoundName.isEmpty() 方法:
方案一:
// Java program to demonstrate
// CompoundName.isEmpty()
import java.util.Properties;
import javax.naming.CompoundName;
import javax.naming.InvalidNameException;
public class GFG {
public static void main(String[] args)
throws InvalidNameException
{
// need properties for CompoundName
Properties props = new Properties();
props.put("jndi.syntax.separator", ":");
props.put("jndi.syntax.direction",
"left_to_right");
// create compound name object
CompoundName CompoundName1
= new CompoundName(
"a:b:z:y:x", props);
// apply isEmpty()
boolean isEmpty
= CompoundName1.isEmpty();
// print value
System.out.println("This Compound "
+ "object is empty:"
+ isEmpty);
}
}
输出:
This Compound object is empty:false
方案二:
// Java program to demonstrate
// CompoundName.isEmpty() method
import java.util.Properties;
import javax.naming.CompoundName;
import javax.naming.InvalidNameException;
public class GFG {
public static void main(String[] args)
throws InvalidNameException
{
// need properties for CompoundName
Properties props = new Properties();
props.put("jndi.syntax.separator", "/");
props.put("jndi.syntax.direction",
"left_to_right");
// create compound name object
CompoundName CompoundName1
= new CompoundName(
"", props);
// apply isEmpty()
boolean isEmpty
= CompoundName1.isEmpty();
// print value
System.out.println("This Compound "
+ "object is empty:"
+ isEmpty);
}
}
输出:
This Compound object is empty:true
参考资料:https://docs.oracle.com/javase/10/docs/api/javax/naming/CompoundName.html#isEmpty()