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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。