Java Collections Shorts 2: ArrayLists methods addAll and retainAll

preview_player
Показать описание
Task 1- Part 2 :Java Collections Shorts 2 ArrayLists
Today’s goals: Compare two array list objects to check if they have any common elements.
Apply retainAll and addAll methods.
Also copy a list into an empty string list with forEach.

1- Create two arraylists, cars and vehicles.

2- Check out how addAll method can be used.
ArrayList{String} cars = new ArrayList{}();
ArrayList{String} vehicles = new ArrayList{}();
// copy all elements in one arraylist into another arraylist

3- Print out the cars and vehicles and validate if they are combined.

4- Compare two array list objects and print out the common elements.
// Compare cars and vehicles and print the common elements
5 - Print Out the common elements:
Рекомендации по теме
Комментарии
Автор

Hi everyone. Just a correction: Also copy a list into an empty string list with forEach.

BeeHabLearning