当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。