If I have: linkedlist1= 1,2,3,4; and linkedlist2= 5,6,7;
Am I able to attach linkedlist2 to the end of linkedlist1 in such a way if I invoke: linkedlist2.set(0,9999) it changes to linkedlist2 = [999,6,7] and linkedlist1 becomes [1,2,3,4,9999,7,8]; ?
Is that possible ? Or I do need another structure ?
The following code didn’t work:
List<Double> l1 = new LinkedList<Double>(Arrays.asList(1.0,2.0));
List<Double> l2 = new LinkedList<Double>(Arrays.asList(3.0,4.0));
l1.addAll(l2);
System.out.println(l1);
l2.set(0, 9.0);
System.out.println(l1);
OUTPUT:
[1.0, 2.0, 3.0, 4.0]
[1.0, 2.0, 3.0, 4.0]
The standard LinkedList classes provided with Java lack this capability.
As Donal Boyle posts you can add the contents of one list to another but this doesn’t maintain the linkage as your describe.