LinkedListlist1 = new LinkedList<>(); list1.add("apple"); list1.add("banana"); LinkedList list2 = (LinkedList ) list1.clone();
LinkedListThis code creates two LinkedList objects, adds some elements to list1, clones it to list2, and then adds and removes some elements from list2. The result is that both list1 and list2 contain different elements. The LinkedList class is a part of the java.util package, which is a part of the Java API library.list1 = new LinkedList<>(); list1.add("apple"); list1.add("banana"); LinkedList list2 = (LinkedList ) list1.clone(); list2.add("cherry"); list2.remove("apple");