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()
相關用法
- Java CompoundName add()用法及代碼示例
- Java CompoundName get()用法及代碼示例
- Java CompoundName isEmpty()用法及代碼示例
- Java CompoundName addAll()用法及代碼示例
- Java CompoundName endsWith()用法及代碼示例
- Java CompoundName getAll()用法及代碼示例
- Java CompoundName getPrefix()用法及代碼示例
- Java CompoundName getSuffix()用法及代碼示例
- Java CompoundName remove()用法及代碼示例
- Java CompoundName toString()用法及代碼示例
- Java CompoundName clone()用法及代碼示例
- Java CompoundName compareTo()用法及代碼示例
- Java CompoundName equals()用法及代碼示例
- Java CompoundName startsWith()用法及代碼示例
- Java CompoundName hashCode()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 CompoundName size() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。