The fair exchange

Report a typo

You're working with the two lists: LinkedList and ArrayList filled with String elements. You need to implement the changeHeadsAndTails method that should change the beginnings and the ends of the lists, so that:

  • the first element of the ArrayList will become the first element of the LinkedList and vice versa;
  • the last element of the ArrayList will become the last element of the LinkedList and vice versa.

The example illustrates the idea:

// original lists
LinkedList [f, b, c, d, j] 
ArrayList  [a, g, h, i, e]

//after the changeHeadsAndTails method invocation
LinkedList [a, b, c, d, e]
ArrayList  [f, g, h, i, j]
Write a program in Java 17
class ListOperations {
public static void changeHeadsAndTails(LinkedList<String> linkedList, ArrayList<String> arrayList) {
// write your code here

}
}
___

Create a free account to access the full topic