I have two LinkedList
s in Java and I would like to prepend all elements of one list to another. Is there a native way to do this in O(1) time? I know all that needs to be done is set the last pointer of the first list to the first of the second list, but there doesn't seem to be a native method to do this.
Also, to add to the complexity of this, I need a way to prepend the list to another one and not append it. I have list A and B, and I need all elements of B to be prepended to list A. I can't just add the elements of A to the end of B because I want to list A to be modified.
Is there a way to do this without having to implement my own LinkedList
?