Advertisement
GlukAlex

Collections_Framework

Feb 25th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. import java.util.Collections;;
  2. import java.util.Map;
  3. import java.util.List;
  4. import java.util.Arrays;
  5. import java.util.stream.Collectors;
  6. // Collections_Framework
  7.  
  8. class /*Main*/Collections_Framework {
  9.   //
  10.   public static void main(String[] args) {
  11.     //
  12.     Map<String, Integer> s_M = Collections.singletonMap("key_1", 1);
  13.     //
  14.     System.out.println("hello world");
  15.     System.out.println(s_M);
  16.     s_M.forEach((k, v) -> {
  17.         System.out.println("k:" + k);
  18.         System.out.println("v:" + v);
  19.       }
  20.     );
  21.     System.out.println(s_M.entrySet());
  22.     System.out.println(s_M.entrySet().toArray()[0]);
  23.     //
  24.     List<Character> l_C = Collections.nCopies(9, '#');
  25.     //
  26.     System.out.println(l_C);
  27.     // fromIndex, inclusive, and toIndex, exclusive
  28.     List<Character> sub_L_3 = l_C.subList(0, 3);
  29.     //
  30.     System.out.println(sub_L_3);
  31.     //CharSequence
  32.     char[] chars = new char[9];
  33.     System.out.println(
  34.       sub_L_3
  35.         .stream()
  36.         .map(i -> i.toString())
  37.         .collect(Collectors.joining(""))
  38.     );
  39.     System.out.println(sub_L_3.listIterator(0).next());
  40.     /// ### .mkString analog ### ///
  41.     List<Integer> numbers = Arrays.asList(1, 2, 3, 4);
  42.     String commaSeparatedNumbers = numbers
  43.       .stream()
  44.       .map(i -> i.toString())
  45.       .collect(Collectors.joining(", "));
  46.     //  
  47.     System.out.println(commaSeparatedNumbers);
  48.     //
  49.   }
  50.   //
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement