Created
December 24, 2021 08:27
-
-
Save gauravkukade/e9323411ee8d6d9c694bbda9653510c6 to your computer and use it in GitHub Desktop.
A Java program to add all elements of the specified collection to the end of the ArrayList. Read more at https://coderolls.com/arraylist-addall-method-in-java/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* A Java program to add all elements of the specified collection | |
* to the end of the ArrayList | |
* | |
* @author Gaurav Kukade at coderolls.com | |
*/ | |
public class ArrayListAddAllExample { | |
public static void main(String[] args) { | |
// ArrayList contains actresses | |
List<String> actresses1 = new ArrayList<String>(); | |
actresses1.add("Natalie Portman"); | |
actresses1.add("Abigail Anderson"); | |
actresses1.add("Jennifer Lawrence"); | |
System.out.println("Actresses collection 1: \n"+ actresses1 ); | |
// ArrayList contains actresses | |
List<String> actresses2 = new ArrayList<String>(); | |
actresses2.add("Angelina Jolie"); | |
actresses2.add("Scarlett Johansson"); | |
System.out.println("Actresses collection 2: \n"+ actresses2); | |
// Add actresses2 collections all elements to actresses1 collection using addAll()method | |
actresses1.addAll(actresses2); | |
System.out.println("Actresses : \n"+ actresses1); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Actresses collection 1: | |
[Natalie Portman, Abigail Anderson, Jennifer Lawrence] | |
Actresses collection 2: | |
[Angelina Jolie, Scarlett Johansson] | |
Actresses : | |
[Natalie Portman, Abigail Anderson, Jennifer Lawrence, Angelina Jolie, Scarlett Johansson] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment