Write a program using Java to move the last element of a LL to the beginning of the list.
public static void main (String[] args) {
LinkedList<Integer> ll = new LinkedList<>();
ll.add(1);
ll.add(2);
ll.add(3);
ll.add(4);
ll.add(5);
ll.add(6);
System.out.println(ll);
int lastElement = ll.getLast();
ll.removeLast();
ll.addFirst(lastElement);
System.out.println(ll);
}
Comments
Leave a comment