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:
import java.util.Properties;
import javax.naming.CompoundName;
import javax.naming.InvalidNameException;
public class GFG {
public static void main(String[] args)
throws InvalidNameException
{
Properties props = new Properties();
props.put( "jndi.syntax.separator" , ":" );
props.put( "jndi.syntax.direction" ,
"left_to_right" );
CompoundName CompoundName1
= new CompoundName(
"a:b:z:y:x" , props);
CompoundName CompoundName2
= new CompoundName(
"z:y:x" , props);
boolean endWithFlag
= CompoundName1
.endsWith(CompoundName2);
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:
import java.util.Properties;
import javax.naming.CompoundName;
import javax.naming.InvalidNameException;
public class GFG {
public static void main(String[] args)
throws InvalidNameException
{
Properties props = new Properties();
props.put( "jndi.syntax.separator" , "/" );
props.put( "jndi.syntax.direction" ,
"left_to_right" );
CompoundName CompoundName1
= new CompoundName(
"c/e/d/v/a/b/z/y/x/f" ,
props);
CompoundName CompoundName2
= new CompoundName(
"z/y/x" ,
props);
boolean endWithFlag
= CompoundName1
.endsWith(CompoundName2);
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)
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
27 Mar, 2020
Like Article
Save Article