Java tutorial
import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; public class Main { public static void main(String[] args) throws Exception { long uniqueWords = Files.lines(Paths.get("Main.java"), Charset.defaultCharset()) .flatMap(line -> Arrays.stream(line.split(" "))).distinct().count(); System.out.println("There are " + uniqueWords + " unique words in data.txt"); } }