javax.naming.CompoundName类的addAll()方法用于将不同化合物名称对象的所有组件添加到此CompoundName对象。有两种不同的addAll()方法。
- addAll(int,名称):此方法用于添加另一个复合名称对象的所有组件,该复合名称作为参数传递到此复合名称对象中指定位置posn。在第一个新组件的位置或之后出现的此复合名称对象的其他组件将上移以容纳不同组件的所有组件。
用法:
public Name addAll(int posn, Name n) throws InvalidNameException
参数:此方法接受:
- posn这是添加所有新组件的索引,并且
- n这是要添加的非null组件。
返回值:此方法返回更新的compoundName对象,而不是新对象。返回的值不能为空。
异常:如果posn不在指定范围内,则此方法引发ArrayIndexOutOfBoundsException;如果n不是复合名称,或者组件的添加违反了此复合名称的语法(例如超过组件数目),则抛出InvalidNameException。
以下示例程序旨在说明CompoundName.addAll()方法:
程序1:// Java program to demonstrate // CompoundName.addAll() 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( "1@2@3@4@5@6@7", props); // different component to add at position 0 CompoundName diffrenetComponent = new CompoundName( "9@99@999@9999", props); // apply addAll() to add All // new components at posn 0 CompoundName newCompoundName = (CompoundName) CompoundName1.addAll( 0, diffrenetComponent); // print value System.out.println( "Updated CompoundName Object:" + newCompoundName); } }
输出:Updated CompoundName Object:9@99@999@9999@1@2@3@4@5@6@7
- addAll(String):Thie方法用于将经过输入的不同复合名称对象的所有组件添加到该复合名称的末尾。
用法:public Name addAll(Name suffix) throws InvalidNameException
参数:此方法接受后缀,该后缀是要添加的非null组件。
返回值:此方法返回更新的compoundName,而不是新的。返回的值不能为空。
异常:如果后缀不是复合名称,或者添加的组件违反了此复合名称的语法(例如,超出组件数量),则此方法将引发InvalidNameException。
以下示例程序旨在说明CompoundName.addAll()方法:
程序1:// Java program to demonstrate // CompoundName.addAll() 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( "1@2@3@4@5@6@7", props); // different component to add at position 0 CompoundName diffrenetComponent = new CompoundName( "9@99@999@9999", props); // apply addAll() to add All // new components at posn 0 CompoundName newCompoundName = (CompoundName) CompoundName1.addAll( diffrenetComponent); // print value System.out.println( "Updated CompoundName Object:" + newCompoundName); } }
输出:Updated CompoundName Object:1@2@3@4@5@6@7@9@99@999@9999
参考文献:
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)
相关用法
- Java CompoundName get()用法及代码示例
- Java CompoundName add()用法及代码示例
- Java CompoundName getPrefix()用法及代码示例
- Java CompoundName remove()用法及代码示例
- Java CompoundName startsWith()用法及代码示例
- Java CompoundName clone()用法及代码示例
- Java CompoundName compareTo()用法及代码示例
- Java CompoundName toString()用法及代码示例
- Java CompoundName endsWith()用法及代码示例
- Java CompoundName equals()用法及代码示例
- Java CompoundName size()用法及代码示例
- Java CompoundName isEmpty()用法及代码示例
- Java CompoundName getAll()用法及代码示例
- Java CompoundName getSuffix()用法及代码示例
- Java CompoundName hashCode()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 CompoundName addAll() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。