×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Added: May 5, 2021 3:23 PM
Modified: May 5, 2021 3:23 PM
Views: 3982
Tags: collections
  1.  
  2.     public static void main(String[] args) {
  3.  
  4.  
  5.         //ArrayList anlegen
  6.         ArrayList<String> colors = new ArrayList<>();
  7.         //Neue ArrayList anlegen
  8.         ArrayList<String> newcolors = new ArrayList<>();
  9.         //Elemente mit .add hinzufügen
  10.         colors.add("Red");
  11.         colors.add("Green");
  12.         colors.add("Orange");
  13.         colors.add("White");
  14.         colors.add("Black");
  15.  
  16.  
  17.         newcolors.add("1");
  18.         newcolors.add("2");
  19.         newcolors.add("3");
  20.         newcolors.add("4");
  21.         newcolors.add("5");
  22.  
  23.         //Erste Methode: for-each:
  24.         for (String c : colors) {
  25.             System.out.println(c);
  26.         }
  27.  
  28.         /*
  29.         Zweite Methode:
  30.         for (int i = 0; i < colors.size(); i++){
  31.          System.out.println(colors.get(i));
  32.         }
  33.          */
  34.     }
  35. }
  36.