Saturday, November 22, 2025
HomeLanguagesJavaCompositeName endsWith() method in Java with Examples

CompositeName endsWith() method in Java with Examples

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 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 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)

RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS