Created
December 5, 2017 23:15
-
-
Save plateauu/e9b3f030d7843e39a20e9243e2a1cfed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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