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


Java CompoundName size()用法及代码示例


javax.naming.CompoundName类的size()方法用于返回化合物名称对象的大小,该大小等于此化合物名称中的组件数。

用法:

public int size()

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



返回值:此方法在此化合物名称中返回非负数的组件。

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

// Java program to demonstrate 
// CompoundName.size() 
  
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 CompoundName1 
            = new CompoundName( 
                "a:b:z:y:x", props); 
  
        // apply size() 
        int size = CompoundName1.size(); 
  
        // print value 
        System.out.println("size:"
                           + size); 
    } 
}
输出:
size:5

程序2:

// Java program to demonstrate 
// CompoundName.size() method 
  
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 CompoundName1 
            = new CompoundName( 
                "c/e/d/v/a/b/z/y/x/f", 
                props); 
  
        // apply size() 
        int size = CompoundName1.size(); 
  
        // print value 
        System.out.println("size:" + size); 
    } 
}
输出:
size:9

参考文献:https://docs.oracle.com/javase/10/docs/api/javax/naming/CompoundName.html#size()




相关用法


注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 CompoundName size() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。