Java9 中對集合類擴充的 of 方法
package com.jd.collections;
import org.junit.Test;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class StreamTest {
@Test
public void testSet() {
Set<Integer> integerSet = Set.of(, , , , , , , );
System.out.println(integerSet);
}
@Test
public void testList() {
List<Integer> integerSet = List.of(, , , , , , , );
System.out.println(integerSet);
}
@Test
public void testMap() {
Map<String, String> stringMap = Map.of("k1", "v1", "k2", "v2", "k3", "v3");
System.out.println(stringMap);
Map.Entry<String, String> entry1 = Map.entry("k1", "v1");
Map.Entry<String, String> entry2 = Map.entry("k11", "v11");
Map.Entry<String, String> entry3 = Map.entry("k12", "v12");
Map<String, String> mapOfEntries = Map.ofEntries(entry1, entry2, entry3);
System.out.println(mapOfEntries);
}
@Test
public void testStream1() {
Optional<Integer> integerOptional = Stream.ofNullable(Integer.valueOf("1232")).findAny();
System.out.println(integerOptional.get());
}
@Test
public void testStream2() {
Stream.of(, , , , , ).dropWhile(x -> x == )/*.takeWhile(x -> x == 2)*/.forEach(System.out::println);
}
@Test
public void testStream3() {
IntStream.of(, , , , , ).forEach(System.out::println);
}
@Test
public void testStream4() {
IntStream.iterate(, i -> i < , i -> i + ).forEach(System.out::println);
}
// @Test
// public void testFlow() {
// Flow.Processor
// }
}