Open In App

CompositeName endsWith() method in Java with Examples

Last Updated : 27 Mar, 2020
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report
The endsWith() method of a javax.naming.CompositeName class is used to check whether composite name which is passed as a parameter is a suffix of this composite name or not. A composite name 'X' is a suffix of this composite name if this composite name object ends with 'X'. If X is null or not a composite name object, false is returned. Syntax:
public boolean endsWith(Name n)
Parameters: This method accepts n which is the possibly null composite name to check. Return value: This method returns true if n is a CompositeName and is a suffix of this composite name, false otherwise. Below programs illustrate the CompositeName.endsWith() method: Program 1: Java
// Java program to demonstrate
// CompositeName.endsWith()

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/3/4/5/6");
        CompositeName CompositeName2
            = new CompositeName("5/6");

        // apply endsWith()
        boolean endWithFlag
            = CompositeName1.endsWith(CompositeName2);

        // print value
        if (endWithFlag)
            System.out.println("CompositeName1 ends with "
                               + " CompositeName2");
        else
            System.out.println("CompositeName1 not ends with "
                               + " CompositeName2");
    }
}
Output:
CompositeName1 ends with  CompositeName2
Program 2: Java
// Java program to demonstrate
// CompositeName.endsWith() 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("c/e/d/v/a/b/z/y/x/f");
        CompositeName CompositeName2
            = new CompositeName("z/y/x");

        // apply endsWith()
        boolean endWithFlag
            = CompositeName1.endsWith(CompositeName2);

        // print value
        if (endWithFlag)
            System.out.println("CompositeName1 ends with "
                               + " CompositeName2");
        else
            System.out.println("CompositeName1 not ends with "
                               + " CompositeName2");
    }
}
Output:
CompositeName1 not ends with  CompositeName2
References: https://docs.oracle.com/javase/10/docs/api/javax/naming/CompositeName.html#endsWith(javax.naming.Name)

Article Tags :
Practice Tags :

Similar Reads