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
public RandomWords() throws IOException { | |
try (BufferedReader reader = Files.newBufferedReader(Paths.get("words.txt"))) { | |
sourceWords = | |
reader | |
.lines() | |
.collect(Collectors.toList()); | |
} | |
} |
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
private def exercise7() { | |
val list = | |
Source.fromFile("SonnetI.txt") | |
.getLines() | |
.flatMap(line => line.split(WORD_REGEXP)) | |
.map(_.toLowerCase) | |
.toSeq | |
.distinct | |
.sortBy(_.length) |
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
private def exercise6() { | |
val list = | |
Source.fromFile("SonnetI.txt") | |
.getLines() | |
.flatMap(line => line.split(WORD_REGEXP)) | |
.map(_.toLowerCase) | |
.toSeq | |
.distinct | |
.sorted |
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
private def exercise5() { | |
val list = | |
Source.fromFile("SonnetI.txt") | |
.getLines() | |
.flatMap(line => line.split(WORD_REGEXP)) | |
.toSeq | |
.distinct | |
list.foreach(println) | |
} |
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
private def exercise4() { | |
println(Source.fromFile("SonnetI.txt").getLines().length) | |
} |
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
private def exercise3() { | |
val list = List("The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog") | |
println(list.slice(1, 4).mkString("-")) | |
} |
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
private def exercise2() { | |
val list = | |
List("The", "Quick", "BROWN", "Fox", "Jumped", "Over", "The", "LAZY", "DOG") | |
.filter(_.length % 2 != 0) | |
.map(_.toLowerCase) | |
list.foreach(println) | |
} |
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
private def exercise1() { | |
val list = | |
List("The", "Quick", "BROWN", "Fox", "Jumped", "Over", "The", "LAZY", "DOG") | |
.map(_.toLowerCase) | |
list.foreach(println) | |
} |
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
private void exercise7() throws IOException { | |
try (BufferedReader reader = Files.newBufferedReader( | |
Paths.get("SonnetI.txt"), StandardCharsets.UTF_8)) { | |
List<String> newWords = | |
reader.lines() | |
.flatMap(line -> Stream.of(line.split(WORD_REGEXP))) | |
.map(String::toLowerCase) | |
.distinct() | |
.sorted((aString, anotherString) -> aString.length() - anotherString.length()) |
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
private void exercise6() throws IOException { | |
try (BufferedReader reader = Files.newBufferedReader( | |
Paths.get("SonnetI.txt"), StandardCharsets.UTF_8)) { | |
List<String> newWords = | |
reader.lines() | |
.flatMap(line -> Stream.of(line.split(WORD_REGEXP))) | |
.map(String::toLowerCase) | |
.distinct() | |
.sorted() |