Open In App

CompositeName equals() method in Java with Examples

Last Updated : 27 Mar, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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:




// Java program to demonstrate
// CompositeName.equals()
  
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("x/y/a/b");
        CompositeName compositeName2
            = new CompositeName("x/y/a/b");
  
        // apply equals()
        boolean flag
            = compositeName1.equals(
                compositeName2);
  
        // print value
        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:




// Java program to demonstrate
// CompositeName.equals() method
  
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("c/d/a/b");
        CompositeName compositeName2
            = new CompositeName("e/d/a/b");
  
        // apply equals()
        boolean flag
            = compositeName1.equals(
                compositeName2);
  
        // print value
        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)



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads