首页 > 编程知识 正文

粗糙度及标注方法示例文库,结构化设计方法示例

时间:2023-05-03 16:18:27 阅读:236432 作者:2221

java addall

向量类的addAll()方法 (Vector Class addAll() method)

Syntax:

句法:

public boolean addAll(Collection co); public boolean addAll(int indices, Collection co);

addAll() method is available in java.util package.

addAll()方法在java.util包中可用。

addAll(Collection co) method is used to append all of the objects that exist in the given collection (co) at the last of this List.

addAll(Collection co)方法用于在此List的最后追加给定集合(co)中存在的所有对象。

addAll(int indices, Collection co) method is used to append all of the objects that exist in the given collection (co) into this vector and the element insertion starts at the given indices.

addAll(int index,Collection co)方法用于将给定collection(co)中存在的所有对象附加到此向量中,并且元素插入从给定索引处开始。

These methods may throw an exception at the time of adding an element.

这些方法在添加元素时可能会引发异常。

IndexOutOfBoundsException: This exception may throw when the given parameter is not in a range.IndexOutOfBoundsException :如果给定参数不在范围内,则可能引发此异常。 NullPointerException: This exception may throw when the given parameter is null exists.NullPointerException :当给定参数为null时,可能引发此异常。

These are non-static methods and it is accessible with class objects and if we try to access these methods with the class name then we will get an error.

这些是非静态方法,可通过类对象访问,如果尝试使用类名访问这些方法,则会收到错误消息。

Parameter(s):

参数:

In the first case, addAll(Collection co),

在第一种情况下, addAll(Collection co) ,

Collection co – represents the collection of elements to be appended.

集合co –表示要附加的元素的集合。

In the first case, addAll(int indices, Collection co),

在第一种情况下, addAll(int index,Collection co) ,

int indices – represents the position of starting element to insert from the given collection. int索引 –表示要从给定集合中插入的起始元素的位置。 Collection co – represents the collection of elements to be appended. 集合co –表示要附加的元素的集合。

Return value:

返回值:

In both the cases, the return type of the method is boolean,

在这两种情况下,方法的返回类型均为boolean 。

In the first case, it returns true when all of the objects are appended in the given collection to the end of the list otherwise it returns false.

在第一种情况下,当所有对象的给定集合中附加到列表否则返回false结束就返回true。

In the second case, it returns true when all of the objects are to be appended in the given collection at the given indices successfully otherwise it returns false.

在第二种情况下,当所有对象都将成功添加到给定集合的给定索引处时,它返回true ,否则返回false

Example:

例:

// Java program to demonstrate the example // of addAll() method of Vectorimport java.util.*;public class AddAllOfVector { public static void main(String[] args) { // Instantiates a vector object Vector < String > v = new Vector < String > (10); ArrayList arr_l = new ArrayList(10); // By using add() method is to add // the elements in vector v.add("C"); v.add("C++"); v.add("SFDC"); v.add("JAVA"); // By using add() method is to add // the elements in arr_l arr_l.add("SQL"); arr_l.add("DBMS"); //Display Vector and ArrayList System.out.println("v: " + v); System.out.println("arr_l: " + arr_l); // By using addAll(arr_l) method is used // to add all the given objects exists in // the given collection will be appended // to this vector at the last v.addAll(arr_l); // Display Vector System.out.println("v.addAll(arr_l): " + v); // By using addAll(arr_l,2) method is used // to add all the given objects exists in // the given collection will be appended // to this vector at the given indices v.addAll(2, arr_l); // Display Vector System.out.println("v.addAll(2,arr_l,): " + v); }}

Output

输出量

v: [C, C++, SFDC, JAVA]arr_l: [SQL, DBMS]v.addAll(arr_l): [C, C++, SFDC, JAVA, SQL, DBMS]v.addAll(2,arr_l,): [C, C++, SQL, DBMS, SFDC, JAVA, SQL, DBMS]

翻译自: https://www.includehelp.com/java/vector-addall-method-with-example.aspx

java addall

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。