@Testpublic void convertStringToUpperCaseStreams() {List<String> collected = Stream.of("a", "b", "hello") // Stream of String.map(String::toUpperCase) // Returns a stream consisting of the results of applying the given function to the elements of this stream..collect(Collectors.toList());assertEquals(asList("A", "B", "HELLO"), collected);}
String[] arrayOfWords = {"STACK", "OOOVVVER"};Stream<String> streamOfWords = Arrays.stream(arrayOfWords);streamOfWords.map(s->s.split("")) //Converting word in to array of letters.map(Arrays::stream).distinct() //Make array in to separate stream.collect(Collectors.toList());
String[] arrayOfWords = {"STACK", "OOOVVVER"};Stream<String> streamOfWords = Arrays.stream(arrayOfWords);streamOfWords.map(s->s.split("")) //Converting word in to array of letters.flatMap(Arrays::stream).distinct() //flattens each generated stream in to a single stream.collect(Collectors.toList());