public Object getFirst() public Object getLast()
import java.util.LinkedList; public class MainClass { public static void main(String[] a) { LinkedList list = new LinkedList(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); list.addFirst("X"); list.addLast("Z"); System.out.println(list); System.out.println(list.getFirst()); System.out.println(list.getLast()); } }
[X, A, B, C, D, Z] X Z