LinkedList: addLast(E o) : LinkedList « java.util « Java by API






LinkedList: addLast(E o)

 
/**
 *Output: 
Original contents of ll: [A, A2, B, C, D, E, F, Z]
Contents of ll after deletion: [A, A2, C, D, E, Z]
ll after deleting first and last: [A2, C, D, E]
ll after change: [A2, C, D Changed, E]
 */

import java.util.LinkedList;

public class MainClass {
  public static void main(String args[]) {

    LinkedList<String> ll = new LinkedList<String>();

    ll.add("B");
    ll.add("C");
    ll.add("D");
    ll.add("E");
    ll.add("F");
    ll.addLast("Z");
    ll.addFirst("A");

    ll.add(1, "A2");

    System.out.println("Original contents of ll: " + ll);

    ll.remove("F");
    ll.remove(2);

    System.out.println("Contents of ll after deletion: " + ll);

    ll.removeFirst();
    ll.removeLast();

    System.out.println("ll after deleting first and last: " + ll);

    String val = ll.get(2);
    ll.set(2, val + " Changed");

    System.out.println("ll after change: " + ll);
  }
}

           
         
  








Related examples in the same category

1.new LinkedList < E > ()
2.LinkedList: add(E o)
3.LinkedList: add(int index, E element)
4.LinkedList: addFirst(E o)
5.LinkedList: clear()
6.LinkedList: get(int index)
7.LinkedList: getFirst()
8.LinkedList: getLast()
9.LinkedList: indexOf(Object o)
10.LinkedList: iterator()
11.LinkedList: lastIndexOf(Object o)
12.LinkedList: remove(int index)
13.LinkedList: remove(Object o)
14.LinkedList: removeFirst()
15.LinkedList: removeLast()
16.LinkedList: set(int index, E element)
17.LinkedList: subList(int fromIndex, int toIndex)
18.LinkedList: toArray(T[] a)