Computer scienceProgramming languagesJavaWorking with dataCollectionsCollection implementationsThe Collection hierarchy implementations

LinkedList vs. ArrayList

Transfer both lists

Report a typo

You're working with the two lists: LinkedList and ArrayList, containing String elements.

You need to implement the transferAllElements method. All elements of LinkedList should become elements of ArrayList and vice versa.

Note that both lists always have the same size.

Example:

// original lists

LinkedList [0, 1, 2, 3, 4]
ArrayList  [5, 6, 7, 8, 9]

// after the transferAllElements method invocation

LinkedList [5, 6, 7, 8, 9]
ArrayList  [0, 1, 2, 3, 4]
Write a program in Java 17
class ListOperations {
public static void transferAllElements(LinkedList<String> linkedList, ArrayList<String> arrayList) {
// write your code here

}
}

Create a free account to access the full topic