CompositeName equals() method in Java with Examples
Last Updated :
27 Mar, 2020
The equals() method of a javax.naming.CompositeName class is used to compare this CompositeName with the specified object passed as a parameter and checks whether two objects are equal or not. If both objects are equal then the equals() method returns true else false. If passed obj is null or not a composite name then the method returns false. Two composite objects are equal if each component in one is equal to the corresponding component in the other.
Syntax:
public boolean equals(Object obj)
Parameters: This method accepts obj which is the possibly null object to compare against.
Return value: This method returns true if obj is equal to this composite name, false otherwise.
Below programs illustrate the CompositeName.equals() method:
Program 1:
import javax.naming.CompositeName;
import javax.naming.InvalidNameException;
public class GFG {
public static void main(String[] args)
throws InvalidNameException
{
CompositeName compositeName1
= new CompositeName( "x/y/a/b" );
CompositeName compositeName2
= new CompositeName( "x/y/a/b" );
boolean flag
= compositeName1.equals(
compositeName2);
if (flag)
System.out.println( "CompositeName1 is "
+ "equal to CompositeName2" );
else
System.out.println( "CompositeName1 is "
+ "not equal to CompositeName2" );
}
}
|
Output:
CompositeName1 is equal to CompositeName2
Program 2:
import javax.naming.CompositeName;
import javax.naming.InvalidNameException;
public class GFG {
public static void main(String[] args)
throws InvalidNameException
{
CompositeName compositeName1
= new CompositeName( "c/d/a/b" );
CompositeName compositeName2
= new CompositeName( "e/d/a/b" );
boolean flag
= compositeName1.equals(
compositeName2);
if (flag)
System.out.println( "CompositeName1 is "
+ "equal to CompositeName2" );
else
System.out.println( "CompositeName1 is "
+ "not equal to CompositeName2" );
}
}
|
Output:
CompositeName1 is not equal to CompositeName2
References: https://docs.oracle.com/javase/10/docs/api/javax/naming/CompositeName.html#equals(java.lang.Object)
Share your thoughts in the comments
Please Login to comment...