javax.naming.CompoundName类的equals()方法用于比较此CompoundName与作为参数传递的指定对象,并检查两个对象是否相等。如果两个对象相等,则equals()方法返回true,否则返回false。如果传递的obj为null或不是复合名称,则该方法返回false。如果一个组件中的每个组件与另一个组件中的相应组件相等,则两个复合对象相等。
用法:
public boolean equals(Object obj)
参数:此方法接受obj,它是要与之比较的非null对象。
返回值:如果obj等于此复合名称,则此方法返回true,否则返回false。
以下示例程序旨在说明CompoundName.equals()方法:
程序1:
// Java program to demonstrate
// CompoundName.equals()
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(
"x:y:z", props);
CompoundName CompoundName2
= new CompoundName(
"x:y:m", props);
// apply equals()
boolean flag
= CompoundName1
.equals(CompoundName2);
// print value
if (flag)
System.out.println(
"CompoundName1 is "
+ "equal to CompoundName2");
else
System.out.println(
"CompoundName1 is "
+ "not equal to CompoundName2");
}
}
输出:
CompoundName1 is not equal to CompoundName2
程序2:
// Java program to demonstrate
// CompoundName.equals() 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(
"x@y@z@M@n", props);
CompoundName CompoundName2
= new CompoundName(
"x@y@z@M@n", props);
// apply equals()
boolean flag
= CompoundName1.equals(CompoundName2);
// print value
if (flag)
System.out.println(
"CompoundName1 is "
+ "equal to CompoundName2");
else
System.out.println(
"CompoundName1 is "
+ "not equal to CompoundName2");
}
}
输出:
CompoundName1 is equal to CompoundName2
参考文献:https://docs.oracle.com/javase/10/docs/api/javax/naming/CompoundName.html#equals(java.lang.Object)
相关用法
- Java CompoundName add()用法及代码示例
- Java CompoundName get()用法及代码示例
- Java CompoundName endsWith()用法及代码示例
- Java CompoundName startsWith()用法及代码示例
- Java CompoundName getPrefix()用法及代码示例
- Java CompoundName getSuffix()用法及代码示例
- Java CompoundName addAll()用法及代码示例
- Java CompoundName clone()用法及代码示例
- Java CompoundName toString()用法及代码示例
- Java CompoundName getAll()用法及代码示例
- Java CompoundName size()用法及代码示例
- Java CompoundName isEmpty()用法及代码示例
- Java CompoundName compareTo()用法及代码示例
- Java CompoundName hashCode()用法及代码示例
- Java CompoundName remove()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 CompoundName equals() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。