Sunday, February 15, 2026
HomeLanguagesJavaCompoundName endsWith() method in Java with Examples

CompoundName endsWith() method in Java with Examples

The endsWith() method of a javax.naming.CompoundName class is used to check whether compound name which is passed as a parameter is a suffix of this compound name or not. A compound name ‘X’ is a suffix of this compound name if this compound name object ends with ‘X’. If X is null or not a compound name object, false is returned.

Syntax:

public boolean endsWith(Name n)

Parameters: This method accepts n which is the possibly null compound name to check.

Return value: This method returns true if n is a CompoundName and is a suffix of this compound name, false otherwise.

Below programs illustrate the CompoundName.endsWith() method:
Program 1:




// Java program to demonstrate
// CompoundName.endsWith()
  
import java.util.Properties;
import javax.naming.CompoundName;
import javax.naming.InvalidNameException;
  
public class GFG {
    public static void main(String[] args)
        throws InvalidNameException
    {
  
        // need properties for CompoundName
        Properties props = new Properties();
        props.put("jndi.syntax.separator", ":");
        props.put("jndi.syntax.direction",
                  "left_to_right");
  
        // create compound name object
        CompoundName CompoundName1
            = new CompoundName(
                "a:b:z:y:x", props);
        CompoundName CompoundName2
            = new CompoundName(
                "z:y:x", props);
  
        // apply endsWith()
        boolean endWithFlag
            = CompoundName1
                  .endsWith(CompoundName2);
  
        // print value
        if (endWithFlag)
            System.out.println(
                "CompoundName1 ends with "
                + " CompoundName2");
        else
            System.out.println(
                "CompoundName1 not ends with "
                + " CompoundName2");
    }
}


Output:

CompoundName1 ends with  CompoundName2

Program 2:




// Java program to demonstrate
// CompoundName.endsWith() method
  
import java.util.Properties;
import javax.naming.CompoundName;
import javax.naming.InvalidNameException;
  
public class GFG {
    public static void main(String[] args)
        throws InvalidNameException
    {
  
        // need properties for CompoundName
        Properties props = new Properties();
        props.put("jndi.syntax.separator", "/");
        props.put("jndi.syntax.direction",
                  "left_to_right");
  
        // create compound name object
        CompoundName CompoundName1
            = new CompoundName(
                "c/e/d/v/a/b/z/y/x/f",
                props);
        CompoundName CompoundName2
            = new CompoundName(
                "z/y/x",
                props);
  
        // apply endsWith()
        boolean endWithFlag
            = CompoundName1
                  .endsWith(CompoundName2);
  
        // print value
        if (endWithFlag)
            System.out.println(
                "CompoundName1 ends with "
                + " CompoundName2");
        else
            System.out.println(
                "CompoundName1 not ends with "
                + " CompoundName2");
    }
}


Output:

CompoundName1 not ends with  CompoundName2

References: https://docs.oracle.com/javase/10/docs/api/javax/naming/CompoundName.html#endsWith(javax.naming.Name)

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32505 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6880 POSTS0 COMMENTS
Nicole Veronica
12003 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12097 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6966 POSTS0 COMMENTS
Umr Jansen
6954 POSTS0 COMMENTS