Java LinkedList boolean addAll(Collection c)方法,带示例

LinkedList boolean addAll(Collection c)方法 (LinkedList boolean addAll(Collection c) method)

  • This method is available in package java.util.Collection and here, Collection is an interface.

    该方法在java.util.Collection包中可用,在这里, Collection是一个接口。

  • This method is declared in Collection interface and it is implemented by LinkedList class.

    此方法在Collection接口中声明,并且由LinkedList类实现。

  • In this method Collection parameter is the list of elements whose need to insert at the end of LinkedList whether Collection is of ArrayList, LinkedList type, etc.

    在此方法中,Collection参数是元素列表,无论Collection是ArrayList,LinkedList类型等,这些元素都需要在LinkedList的末尾插入。

  • This method is used to insert the collection of objects at the end of the linked list.

    此方法用于在链接列表的末尾插入对象集合。

  • Index position starts from 0.

    索引位置从0开始。

Syntax:

句法:

    boolean addAll(Collection c){
    }

Parameter(s):

参数:

We can pass only one argument as a parameter in the method and the Collection parameter is the collection of elements will append at the ending position of the linked list.

我们只能在方法中传递一个参数作为参数,而Collection参数是元素集合将附加在链表的结尾位置。

Return value:

返回值:

The return type of this method is boolean that means this method returns true during execution of at least inserting of one element.

该方法的返回类型为布尔值 ,这意味着该方法在至少插入一个元素的过程中返回true。

Java程序演示LinkedList addAll(Collection c)方法的示例 (Java program to demonstrate example of LinkedList addAll(Collection c) method)

import java.util.LinkedList;
import java.util.ArrayList;

public class LinkList {
 public static void main(String args[]) {

  // Creating a LinkedList 
  LinkedList list = new LinkedList();

  // Use add() method to add objects 
  // in the LinkedList
  list.add("J");
  list.add("A");
  list.add("V");
  list.add("A");


  // Creating a Collection ArrayList 
  // object of ArrayList Type
  ArrayList al = new ArrayList();
  al.add("P");
  al.add("R");
  al.add("O");
  al.add("G");

  al.add("R");
  al.add("A");
  al.add("M");
  al.add("M");
  al.add("I");
  al.add("N");
  al.add("G");
  // Displaying the Current LinkedList 
  System.out.println("The Current LinkedList is: " + list);

  // Appending the collection ArrayList to the LinkedList 
  // and ArrayList will start inserting elements from Fifth 
  // Position 
  list.addAll(al);

  //  Displaying the new LinkedList
  System.out.println("The new linked list is: " + list);
 }
}

Output

输出量

D:\Programs>javac LinkList.java

D:\Programs>java LinkList
The Current LinkedList is: [J, A, V, A]
The new linked list is: [J, A, V, A, P, R, O, G, R, A, M, M, I, N, G]


翻译自: https://www.includehelp.com/java/linkedlist-boolean-addall-collection-c-method-with-example.aspx

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值