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


Java CompoundName getAll()用法及代碼示例


javax.naming.CompoundName類的getAll()方法用於返回此複合對象的所有組件,作為字符串的枚舉。在此枚舉上應用於此化合物名稱的更新效果是不確定的。

用法:

public Enumeration getAll()

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



返回值:此方法返回此複合名稱的組成部分的非null枚舉。枚舉的每個元素都是String類。

以下示例程序旨在說明CompoundName.getAll()方法:
程序1:

// Java program to demonstrate 
// CompoundName.getAll() 
  
import java.util.Enumeration; 
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 compoundName 
            = new CompoundName( 
                "a:b:z:y:x", 
                props); 
  
        // apply getAll() 
        Enumeration<String> components 
            = compoundName.getAll(); 
  
        // print value 
        int i = 0; 
        while (components.hasMoreElements()) { 
            System.out.println( 
                "position " + i + ":"
                + components.nextElement()); 
            i++; 
        } 
    } 
}
輸出:
position 0:a
position 1:b
position 2:z
position 3:y
position 4:x

程序2:

// Java program to demonstrate 
// CompoundName.getAll() method 
  
import java.util.Enumeration; 
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 compoundName 
            = new CompoundName( 
                "c/e/d/v/a/b/z/y/x/f", 
                props); 
  
        // apply getAll() 
        Enumeration<String> components 
            = compoundName.getAll(); 
  
        // print value 
        int i = 0; 
        while (components.hasMoreElements()) { 
            System.out.println( 
                "position " + i 
                + ":" + components.nextElement()); 
            i++; 
        } 
    } 
}
輸出:
position 0:c
position 1:e
position 2:d
position 3:v
position 4:a
position 5:b
position 6:z
position 7:y
position 8:x
position 9:f

參考文獻:https://docs.oracle.com/javase/10/docs/api/javax/naming/CompoundName.html#getAll()




相關用法


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