MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / RandomWords

Method RandomWords

streams/RandomWords.java:14–22  ·  view source on GitHub ↗
(String fname)

Source from the content-addressed store, hash-verified

12 List<String> words = new ArrayList<>();
13 Random rand = new Random(47);
14 RandomWords(String fname) throws IOException {
15 List<String> lines =
16 Files.readAllLines(Paths.get(fname));
17 // Skip the first line:
18 for(String line : lines.subList(1, lines.size())) {
19 for(String word : line.split("[ .?,]+"))
20 words.add(word.toLowerCase());
21 }
22 }
23 @Override public String get() {
24 return words.get(rand.nextInt(words.size()));
25 }

Callers

nothing calls this directly

Calls 4

splitMethod · 0.80
getMethod · 0.65
sizeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected