Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
25
Task/Ordered-words/Java/ordered-words-2.java
Normal file
25
Task/Ordered-words/Java/ordered-words-2.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
public final class OrderedWords {
|
||||
|
||||
public static void main(String[] aArgs) throws IOException {
|
||||
List<String> ordered = Files.lines(Path.of("unixdict.txt"))
|
||||
.filter( word -> isOrdered(word) ).toList();
|
||||
|
||||
final int maxLength = ordered.stream().map( word -> word.length() ).max(Integer::compare).get();
|
||||
ordered.stream().filter( word -> word.length() == maxLength ).forEach(System.out::println);
|
||||
}
|
||||
|
||||
private static boolean isOrdered(String aWord) {
|
||||
return aWord.chars()
|
||||
.mapToObj( i -> (char) i )
|
||||
.sorted()
|
||||
.map(String::valueOf)
|
||||
.reduce("", String::concat)
|
||||
.equals(aWord);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue