javax.naming.CompositeName类的get()方法用于获取此复合名称对象的组件。位置作为参数传递,用于从复合名称对象获取该位置上存在的组件。
用法:
public String get(int posn)
参数:此方法接受posn,它是要检索的组件的从0开始的索引。必须在[0,size())范围内。
返回值:此方法返回索引posn处的组件。
异常:如果posn在指定范围之外,则此方法引发ArrayIndexOutOfBoundsException。
下面的程序说明CompositeName.get()方法:
程序1: 
// Java program to demonstrate 
// CompositeName.get() 
  
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/baz/ay/x"); 
  
        // apply get() 
        String comp1 = CompositeName1.get(0); 
        String comp2 = CompositeName1.get(3); 
  
        // print value 
        System.out.println(comp1); 
        System.out.println(comp2); 
    } 
}
输出:
a x
程序2:
// Java program to demonstrate 
// CompositeName.get() 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( 
                "c/e/d/v/a/b/z/y/x/f"); 
  
        // apply get() 
        String pos3 = CompositeName1.get(3); 
        String pos4 = CompositeName1.get(4); 
  
        // print value 
        System.out.println( 
            "Component at position 3:"
            + pos3); 
        System.out.println( 
            "Component at position 4:"
            + pos4); 
    } 
}
输出:
Component at position 3:v Component at position 4:a
参考文献:https://docs.oracle.com/javase/10/docs/api/javax/naming/CompositeName.html#get(int)
相关用法
- Java CompositeName add()用法及代码示例
 - Java CompositeName endsWith()用法及代码示例
 - Java CompositeName startsWith()用法及代码示例
 - Java CompositeName remove()用法及代码示例
 - Java CompositeName isEmpty()用法及代码示例
 - Java CompositeName getSuffix()用法及代码示例
 - Java CompositeName getPrefix()用法及代码示例
 - Java CompositeName hashCode()用法及代码示例
 - Java CompositeName toString()用法及代码示例
 - Java CompositeName toString()用法及代码示例
 - Java CompositeName compareTo()用法及代码示例
 - Java CompositeName addAll()用法及代码示例
 - Java CompositeName equals()用法及代码示例
 - Java CompositeName clone()用法及代码示例
 - Java CompositeName size()用法及代码示例
 
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 CompositeName get() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
