當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java CompositeName isEmpty()用法及代碼示例


javax.naming.CompositeName類的isEmpty()方法用於檢查此複合名稱對象是否為空。如果複合名稱包含零個組成部分,則稱該名稱為空。

用法:

public boolean isEmpty()

參數:此方法不接受任何內容。



返回值:如果此複合名稱為空,則此方法返回true,否則返回false。

下麵的程序說明CompositeName.isEmpty()方法:
程序1:

// 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

程序2:

// 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()




相關用法


注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 CompositeName isEmpty() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。