public static void main(String[] args) { //Stream(流)是一個來自數據源的元素隊列並支持聚合操作 //聚合操作:類似SQL語句一樣的操作, 比如filter, map, reduce, find, match, sorted等。 Random random = new Random(); random.ints().limit(3).forEach(System.out::println); final Stream<String> stream = Stream.of("Red", "Blue", "Green"); stream.forEach(System.out::println); IntStream intStream = IntStream.of(10, 20, 30); intStream.forEach(System.out::println); List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd", ""); Stream<String> countStream = strings.stream().filter(string -> string.isEmpty()); long count = countStream.count(); System.out.println("count:" + count); final Stream<String> sortStream = Stream.of("Red", "Blue", "Green"); sortStream.sorted().forEach(System.out::println); Integer fst = 127; Integer snd = new Integer(127); System.out.println(fst == snd); //false System.out.println(new Integer(127) == snd); //false System.out.println(fst == Integer.valueOf(127));//true Integer trd = 128; System.out.println(trd == Integer.valueOf(128)); //false }