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 = mutable.MutableList("alpha", "bravo", "charlie", "delta", "echo", "foxtrot") | |
list.transform(_.toUpperCase) | |
println(list) | |
} |
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() { | |
new Thread(new Runnable { | |
def run() { | |
List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) | |
.foreach(print) | |
} | |
}).start() | |
} |
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() { | |
val result = new StringBuilder() | |
val map = TreeMap(("c", 3), ("b", 2), ("a", 1)) | |
map | |
.map(entry => entry._1 + entry._2) | |
.foreach(result.append) | |
println(result) | |
} |
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 exercise1() { | |
List<String> list = Arrays.asList( | |
"The", "Quick", "BROWN", "Fox", "Jumped", "Over", "The", "LAZY", "DOG"); | |
List<String> newList = | |
list | |
.stream() | |
.map(String::toLowerCase) | |
.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 void exercise2() { | |
List<String> list = Arrays.asList( | |
"The", "Quick", "BROWN", "Fox", "Jumped", "Over", "The", "LAZY", "DOG"); | |
List<String> newList = | |
list | |
.stream() | |
.filter(word -> word.length() % 2 != 0) | |
.map(String::toLowerCase) | |
.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 void exercise3() { | |
List<String> list = Arrays.asList( | |
"The", "Quick", "BROWN", "Fox", "Jumped", "Over", "The", "LAZY", "DOG"); | |
String string = | |
list | |
.stream() | |
.skip(1) | |
.limit(3) | |
.collect(Collectors.joining("-")); |
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 exercise4() throws IOException { | |
try (BufferedReader reader = Files.newBufferedReader( | |
Paths.get("SonnetI.txt"), StandardCharsets.UTF_8)) { | |
System.out.println(reader.lines().count()); | |
} | |
} |
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 exercise5() 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))) | |
.distinct() | |
.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 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() |
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()) |