Ordered words: Difference between revisions

New post of program using Java 16 syntax in addition to an existing Java example which was retained.
mNo edit summary
(New post of program using Java 16 syntax in addition to an existing Java example which was retained.)
Line 2,617:
glossy
knotty</pre>
 
===Using Java 16===
<syntaxhighlight lang="java">
 
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("C:/Users/psnow/Desktop/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);
}
 
}
</syntaxhighlight>
<pre>
The same as the Java example above.
</pre>
 
=={{header|JavaScript}}==
908

edits