Page 44 - Abstract Class, Interface & Struktur Data
P. 44

addFirst












                                                  import java.util.LinkedList;



                                                  public class Main {

                                                    public static void main(String[] args) {

                                                      LinkedList<String> cars = new LinkedList<String>();
                                                      cars.add("Volvo");

                                                      cars.add("BMW");

                                                      cars.add("Ford");



                                                      // Use addFirst() to add the item to the beginning

                                                      cars.addFirst("Mazda");
                                                      System.out.println(cars);

                                                    }

                                                  }
   39   40   41   42   43   44   45   46   47   48   49