Skip to content

Instantly share code, notes, and snippets.

@plateauu
Created December 5, 2017 23:15
Show Gist options
  • Save plateauu/e9b3f030d7843e39a20e9243e2a1cfed to your computer and use it in GitHub Desktop.
Save plateauu/e9b3f030d7843e39a20e9243e2a1cfed to your computer and use it in GitHub Desktop.
package com.plateauu.abstractTest;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
class Splitter {
private static List<String> vowels = Arrays.asList("a", "e", "y", "u", "i", "o");
public static void main(String[] args) {
String fileString = System.getProperty("user.dir") + "/src/com/plateauu/abstractTest/txt.txt";
try (Stream<String> stream = Files.lines(Paths.get(fileString))) {
stream
.flatMap(s -> Stream.of(s.split("\\s")))
.filter(Splitter::hasFiveVowels)
.forEach(s -> System.out.println(" " + s + " "));
} catch (IOException e) {
e.printStackTrace();
}
}
private static boolean hasFiveVowels(String word) {
List<Character> wordLetters = new ArrayList<>();
for(int i = 0; i < word.length(); i++) {
wordLetters.add(word.charAt(i));
}
long count = wordLetters
.stream()
.filter(o -> vowels.contains(o.toString()))
.distinct()
.count();
return count > 4;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment