Open In App

CompositeName equals() method in Java with Examples

Last Updated : 27 Mar, 2020
Comments
Improve
Suggest changes
Like Article
Like
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
// 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
// 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)

Article Tags :
Practice Tags :

Similar Reads