javax.naming.CompositeName類的startsWith()方法用於檢查作為參數傳遞的複合名稱是否為此複合名稱的前綴。如果此複合名稱對象以“ X”結尾,則複合名稱“ X”是該複合名稱的前綴。如果X為null或不是複合名稱對象,則返回false。
用法:
public boolean startsWith(Name n)
參數:此方法接受Name對象n,該對象可能是要檢查的複合名稱。
返回值:如果n是CompositeName且是此複合名稱的前綴,則此方法返回true,否則返回false。
下麵的程序說明CompositeName.startsWith()方法:
程序1:
// Java program to demonstrate
// CompositeName.startsWith()
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("1:2:4:6");
CompositeName CompositeName2
= new CompositeName("2:4:6");
// apply startsWith()
boolean Flag
= CompositeName1
.startsWith(CompositeName2);
// print value
if (Flag)
System.out.println(
"CompositeName1 starts with "
+ " CompositeName2");
else
System.out.println(
"CompositeName1 not starts with "
+ " CompositeName2");
}
}
輸出:
CompositeName1 not starts with CompositeName2
程序2:
// Java program to demonstrate
// CompositeName.startsWith() 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(
"ca/eaaa/daaa/vaaa/a/b/z/y/x/f");
CompositeName CompositeName2
= new CompositeName(
"ca/eaaa/daaa");
// apply startsWith()
boolean Flag
= CompositeName1
.startsWith(CompositeName2);
// print value
if (Flag)
System.out.println(
"CompositeName1 starts with "
+ " CompositeName2");
else
System.out.println(
"CompositeName1 not starts with "
+ " CompositeName2");
}
}
輸出:
CompositeName1 starts with CompositeName2
相關用法
- Java CompositeName get()用法及代碼示例
- Java CompositeName add()用法及代碼示例
- Java CompositeName compareTo()用法及代碼示例
- Java CompositeName size()用法及代碼示例
- Java CompositeName getAll()用法及代碼示例
- Java CompositeName clone()用法及代碼示例
- Java CompositeName getPrefix()用法及代碼示例
- Java CompositeName endsWith()用法及代碼示例
- Java CompositeName equals()用法及代碼示例
- Java CompositeName toString()用法及代碼示例
- Java CompositeName getSuffix()用法及代碼示例
- Java CompositeName remove()用法及代碼示例
- Java CompositeName toString()用法及代碼示例
- Java CompositeName addAll()用法及代碼示例
- Java CompositeName hashCode()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 CompositeName startsWith() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。