×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Ellirabeth Dzhurko
Added: Jul 20, 2016 11:28 AM
Modified: Dec 2, 2016 7:17 AM
Views: 2093
Tags: collection
  1. public static void main(String[] args) throws IOException
  2. {
  3.         ArrayList<Integer> result = new ArrayList<Integer>();
  4.         Collections.addAll(result, 1, 8, 6, 21, 53, 5, 67, 18);
  5.         //или
  6.         List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
  7.        
  8.      // Старый способ: //быстрый for по всем элементам, только для коллекций
  9.     for (Integer x: result) {
  10.         System.out.println(x);
  11.     }
  12.    
  13.      // Новый способ:
  14.         list.forEach(n -> System.out.println(n));
  15.        
  16.         // Новый способ с использованием оператора двойного двоеточия ::
  17.         list.forEach(System.out::println);
  18.  
  19.        
  20.         String [][] d = new String [2][3];
  21.         d[0][0] = "1";  d[0][1] = "2";  d[0][2] = "3";
  22.         d[1][0] = "4";  d[1][1] = "5";  d[1][2] = "6";
  23.      System.out.println(Arrays.deepToString(b)); //быстрый вывод всего, что в массиве
  24.  
  25. }