(String[] args)
| 7 | |
| 8 | public class UniqueWords { |
| 9 | public static void |
| 10 | main(String[] args) throws Exception { |
| 11 | List<String> lines = Files.readAllLines( |
| 12 | Paths.get("SetOperations.java")); |
| 13 | Set<String> words = new TreeSet<>(); |
| 14 | for(String line : lines) |
| 15 | for(String word : line.split("\\W+")) |
| 16 | if(word.trim().length() > 0) |
| 17 | words.add(word); |
| 18 | System.out.println(words); |
| 19 | } |
| 20 | } |
| 21 | /* Output: |
| 22 | [A, B, C, Collections, D, E, F, G, H, HashSet, I, J, K, |