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

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

Java中的 CompositeName getAll() 方法及示例

javax.naming.CompositeName 类getAll()方法用于将该复合对象的所有组件作为字符串的枚举返回。在此枚举上应用于此复合名称的更新效果未定义。

句法:

public Enumeration getAll()

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

返回值:此方法返回此复合名称的组件的非空枚举。枚举的每个元素都属于 String 类。

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

// Java program to demonstrate
// CompositeName.getAll()
  
import java.util.Enumeration;
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 CompositeName
            = new CompositeName("a/b/z/y/x");
  
        // apply getAll()
        Enumeration components
            = CompositeName.getAll();
  
        // print value
        while (components.hasMoreElements()) {
            System.out.println("Component: "
                               + components.nextElement());
        }
    }
}

方案二:

// Java program to demonstrate
// CompositeName.getAll() method
  
import java.util.Enumeration;
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 CompositeName
            = new CompositeName("ca/ea/dz/y/x/f");
  
        // apply getAll()
        Enumeration components
            = CompositeName.getAll();
  
        // print value
        int i = 0;
        while (components.hasMoreElements()) {
            System.out.println("position "
                               + i + ": "
                               + components.nextElement());
            i++;
        }
    }
}

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