Java LinkedList addAll() Method | Rookie Tutorial
Rookie Tutorial --
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
Java Tutorial
Java TutorialJava IntroductionJava Environment SetupJava Basic SyntaxJava CommentsJava Objects and ClassesJava Basic Data TypesJava Variable TypesJava Variable Naming RulesJava ModifiersJava OperatorsJava Loop StructureJava Conditional StatementsJava switch caseJava Number & Math ClassJava Character ClassJava String ClassJava StringBufferJava ArrayJava Date and TimeJava Regular ExpressionsJava MethodsJava ConstructorJava Stream, File, IOJava Scanner ClassJava Exception Handling
Java Object-Oriented
Java InheritanceJava Override/OverloadJava PolymorphismJava Abstract ClassJava EncapsulationJava InterfaceJava EnumJava PackageJava Reflection
Java Advanced Tutorial
Java Data StructuresJava Collections FrameworkJava ArrayListJava LinkedListJava HashSetJava HashMapJava IteratorJava ObjectJava NIO FilesJava GenericsJava SerializationJava NetworkingJava Sending EmailJava MultithreadingJava Applet BasicsJava DocumentationJava ExamplesJava 8 New FeaturesJava MySQL ConnectionJava 9 New FeaturesJava QuizJava Common Libraries
Java LinkedList addAll() Method
The addAll() method is a commonly used method provided by the LinkedList class in Java, used to add all elements from one collection to another collection. This method is very useful when handling batch data operations.
Method Syntax
The LinkedList class provides two overloaded forms of the addAll() method:
1. Add elements at the end of the list
boolean addAll(Collection<? extends E> c)
2. Insert elements at a specified position
boolean addAll(int index, Collection<? extends E> c)
Parameter Description
First form parameters
c: The collection of elements to be added, where the element type must be compatible with the LinkedList's element type
Second form parameters
index: The index of the insertion position (starting from 0)
c: The collection of elements to be added
Return Value
Both methods return a boolean value:
true: If the LinkedList is changed as a result of the call
false: If the passed collection is empty or no elements are added
Usage Examples
Basic usage example
Example
import java.util.LinkedList;
import java.util.ArrayList;
public class AddAllExample {
public static void main(String[] args){
// Create two collections
LinkedList<String> linkedList = new LinkedList<>();
ArrayList<String> arrayList
addAll() method is a commonly used method provided by the LinkedList class in Java, used to add all elements from one collection to another collection. This method is very useful when handling batch data operations.LinkedList class provides two overloaded forms of the addAll() method:boolean addAll(Collection<? extends E> c)boolean addAll(int index, Collection<? extends E> c)c: The collection of elements to be added, where the element type must be compatible with the LinkedList's element typeindex: The index of the insertion position (starting from 0)c: The collection of elements to be addedboolean value:true: If the LinkedList is changed as a result of the callfalse: If the passed collection is empty or no elements are addedimport java.util.LinkedList;
import java.util.ArrayList;
public class AddAllExample {
public static void main(String[] args){
// Create two collections
LinkedList<String> linkedList = new LinkedList<>();
ArrayList<String> arrayList
YouTip