Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package opgave4;
- import java.io.File;
- import java.io.IOException;
- import java.util.NoSuchElementException;
- import java.util.Scanner;
- import java.util.Set;
- import java.util.TreeSet;
- public class fromFiletoTreeSet {
- public static void main(String[] args) throws NoSuchElementException {
- Set<String> words = new TreeSet<>();
- int counter = 0;
- try {
- File fileIn = new File("C:\\Users\\Allan Birch\\Desktop\\Skole\\PRO\\Lektioner\\2. Semester\\Lektion 5 - Collection Framework\\Gjøngehøvdingen.txt");
- Scanner scan = new Scanner(fileIn);
- while (scan.hasNext()) {
- String s = scan.next();
- words.add(s);
- counter++;
- }
- System.out.println("There are " + counter + " words in the Set: " + words);
- scan.close();
- } catch (IOException e) {
- System.out.println(e.getMessage());
- }
- }
- }
Add Comment
Please, Sign In to add comment