In my Java application both of the following will compile and run, and produce the desired result.
//"Rotate" the list items one place to the left.
myLinkedList.addLast(myLinkedList.removeFirst());
And a "rotation" in the opposite direction
//"Rotate" the list items one place to the right.
myLinkedList.addFirst(myLinkedList.removeLast());
Both "rotations" only require one line of code each, but I'm wondering if this is the right way to go about it? Are there any pitfalls in this approach?
Is there a better, more robust, less error-prone way of doing the same as I have above which would require more than one line of code to achieve, and if so please explain why.