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