java vector addall_Java Vector addAll()用法及代码示例

java.util.Vector.addAll(int index,Collection C):此方法用于将集合中作为参数传递的所有元素附加到此函数的向量的特定索引或位置。

用法:

boolean addAll(int index, Collection C)

参数:此函数接受上面语法中所示的两个参数,并在下面进行描述。

index:此参数为整数数据类型,并指定向量在矢量中的位置,从该位置开始插入容器中的元素。

C:它是ArrayList的集合。这是需要附加其元素的集合。

返回值:如果至少执行了一个附加操作,则该方法返回True,否则返回False。

以下示例程序旨在说明Java.util.Vector.addAll()方法:

// Java code to illustrate boolean addAll()

import java.util.*;

import java.util.ArrayList;

public class GFG {

public static void main(String args[])

{

// Creating an empty Vector

Vector vt = new Vector();

// Use add() method to add elements in the Vector

vt.add("Geeks");

vt.add("for");

vt.add("Geeks");

vt.add("10");

vt.add("20");

// A collection is created

Collection c = new ArrayList();

c.add("A");

c.add("Computer");

c.add("Portal");

c.add("for");

c.add("Geeks");

// Displaying the Vector

System.out.println("The Vector is: " + vt);

// Appending the collection to the vector

vt.addAll(1, c);

// Clearing the vector using clear() and displaying

System.out.println("The new vector is: " + vt);

}

}

输出:

The Vector is: [Geeks, for, Geeks, 10, 20]

The new vector is: [Geeks, A, Computer, Portal, for, Geeks, for, Geeks, 10, 20]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值