1. Correct Way to Use Optional Consider the following example: List<String> list = new ArrayList<String>(); list.add("java"); list.add("php"); list.add("python"); list.add("perl"); list.add("c"); list.add("lisp"); list.add("c#"); Stream<String> wordStream = list.stream(); Stream<Integer> lengthStream = wordStream.map(s -> s.length()); Optional<Integer> sum = lengthStream.reduce((x, y) -> x + y); System.out.println(sum.get()); This is not correct, as there is no null checking. Instead of […]
↧