Answer to Question #309550 in Java | JSP | JSF for Kyle

Question #309550

Write a program using Java to move the last element of a LL to the beginning of the list.


1
Expert's answer
2022-03-17T08:55:28-0400
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);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS