private static CoolGuys[] array = {
new CoolGuy(1, "Diomidis Spinellis", "dds"),
new CoolGuy(2, "Stefanos Georgiou", "stefanos1316"),
new CoolGuy(3, "Konstantinos Kravvaritis", "kravvaritisk")
};
Stream.of(array);
private static List<CoolGuy> list = Arrays.asList(array);
list.stream();
List<String> myList =
Arrays.asList("a1", "a2", "b1", "c2", "c1");
myList
.stream()
.filter(s -> s.startsWith("c"))
.forEach(System.out::println);
myList
.stream()
.filter(s -> startsWithC().test(s))
.forEach(System.out::println);
public static Predicate<String> startsWithC() {
return s -> s.startsWith("c");
}
Arrays.stream(new int[] {1, 2, 3})
.map(n -> 2 * n + 1)
.forEach(System.out::println);
Stream.of("Department", "of", "Science", "and", "Technology")
.peek(s -> System.out.println(s))
.map(s -> s.toUpperCase())
.forEach(System.out::println);
Optional<String> val = Stream.of("one", "two").findAny();
if (val.isPresent() == true)
System.out.println("There is some values");
Set<String> stringSet = Stream.of("some", "one", "some", "one")
.collect(Collectors.toSet());
IntBinaryOperator binaryOpt = (s1,s2)-> (s1+s2);
int sum = IntStream.of(1, 2, 3, 4).reduce(0, binaryOpt);
System.out.println(sum);
OptionalInt v = IntStream.of(1, 2, 3, 4).reduce(binaryOpt);
System.out.println(v.getAsInt());
Stream<String> stream =
Stream.of("d2", "a2", "b1", "b3", "c")
.filter(s -> s.startsWith("a"));
stream.findFirst(); // ok
stream.findAny(); // exception