CompoundName addAll() method in Java with Examples
Last Updated :
30 May, 2022
The addAll() method of a javax.naming.CompoundName class is used to add all the components of a different compound name object to this CompoundName object.
There are two different addAll() methods.
1. addAll(int, Name): This method is used to add All the components of a different Compound name object which is passed as a parameter at a specified position posn in this compound name object. The other components of this compound name object present at or after the position of the first new component are shifted up to accommodate all the components of the different components.
Syntax:
public Name addAll(int posn, Name n)
throws InvalidNameException
Parameters: This method accepts:
- posn which is the index at which to add all the new components and
- n which is the non-null components to add.
Return value: This method returns updated compoundName object, not a new one. The returned value Cannot be null.
Exception: This method throws ArrayIndexOutOfBoundsException If posn is outside the specified range and InvalidNameException If n is not a compound name, or if the addition of the components violates the syntax of this compound name (e.g. exceeding the number of components).
Below programs illustrate the CompoundName.addAll() method:
Program 1:
Java
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(
"1@2@3@4@5@6@7" ,
props);
CompoundName differentComponent
= new CompoundName(
"9@99@999@9999" ,
props);
CompoundName newCompoundName
= (CompoundName)
CompoundName1.addAll(
0 , diffrenetComponent);
System.out.println(
"Updated CompoundName Object: "
+ newCompoundName);
}
}
|
Output:
Updated CompoundName Object: 9@99@999@9999@1@2@3@4@5@6@7
2. addAll(String): This method is used to add all the components of different compound name object passed as input to the end of this compound name.
Syntax:
public Name addAll(Name suffix)
throws InvalidNameException
Parameters: This method accepts suffix which is the non-null components to add.
Return value: This method returns updated compoundName, not a new one. The returned value Cannot be null.
Exception: This method throws InvalidNameException if the suffix is not a compound name, or if the addition of the components violates the syntax of this compound name (e.g. exceeding the number of components).
Below programs illustrate the CompoundName.addAll() method:
Program 1:
Java
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(
"1@2@3@4@5@6@7" , props);
CompoundName differentComponent
= new CompoundName(
"9@99@999@9999" , props);
CompoundName newCompoundName
= (CompoundName)
CompoundName1.addAll(
diffrenetComponent);
System.out.println(
"Updated CompoundName Object: "
+ newCompoundName);
}
}
|
Output:
Updated CompoundName Object: 1@2@3@4@5@6@7@9@99@999@9999
References:
https://docs.oracle.com/javase/10/docs/api/javax/naming/CompoundName.html#addAll(javax.naming.Name)
https://docs.oracle.com/javase/10/docs/api/javax/naming/CompoundName.html#addAll(int, javax.naming.Name)
Similar Reads
CompoundName add() method in Java with Examples
The add() method of a javax.naming.CompoundName class is used to add the component to the CompoundName object. There are two different add method. add(int, String): This method is used to add a single component at a specified position posn passed as a parameter within this compound name. The other c
4 min read
CompositeName addAll() method in Java with Examples
The addAll() method of a javax.naming.CompositeName class is used to add all the component of a different composite name object to this CompositeName object.There are two different addAll() methods. 1. addAll(int, Name): This method is used to add all the component of a different composite name obje
3 min read
CompositeName add() method in Java with Examples
The add() method of a javax.naming.CompositeName class is used to add the component to the CompositeName object.There are two different add method. 1. add(int, String): This method is used to add a single component at a specified position posn passed as a parameter within this composite name. The ot
3 min read
Collection addAll() method in Java with Examples
The addAll(Collection collection) of java.util.Collection interface is used to add the Collection 'collection' to this existing collection. This method returns a boolean value depicting the successfulness of the operation. If the collection was added, it returns true, else it returns false. Syntax:
3 min read
CompoundName getAll() method in Java with Examples
The getAll() method of a javax.naming.CompoundName class is used to return all the component of this compound object as enumeration of string. The update effects applied to this compound name on this enumeration is undefined. Syntax: public Enumeration getAll() Parameters: This method accepts nothin
2 min read
Collections addAll() method in Java with Examples
The addAll() method of java.util.Collections class is used to add all of the specified elements to the specified collection. Elements to be added may be specified individually or as an array. The behavior of this convenience method is identical to that of c.addAll(Arrays.asList(elements)), but this
3 min read
CompoundName toString() method in Java with Examples
The toString() method of a javax.naming.CompoundName class is used to create the string representation of this compound name object, using the syntax of the compound name which was passed through properties. if the component is empty then it is represented by an empty string. The string representati
2 min read
CopyOnWriteArraySet addAll() method in Java with Examples
The addAll() method of CopyonWriteArraySet method adds all the element of the specified collection to this CopyOnWriteArraySet which are not present in it. This methods results the union of the two collections. Syntax: public boolean addAll(Collection<E> c) Parameters: This method accepts a pa
2 min read
Calendar add() Method in Java with Examples
The add() method of Calendar class present inside is used to add or subtract from the given calendar field(int field), a specific amount of time(int amt), based on the calendar's rules. Syntax: public abstract void add(int field, int amt) Parameters: The method takes two parameters: The field of the
3 min read
Collection add() Method in Java with Examples
The add(E element) of java.util.Collection interface is used to add the element 'element' to this collection. This method returns a boolean value depicting the successfulness of the operation. If the element was added, it returns true, else it returns false. Syntax: Collection.add(E element) Paramet
4 min read