-
Notifications
You must be signed in to change notification settings - Fork 1
/
LietKeTuKhacNhau.java
47 lines (41 loc) · 1.12 KB
/
LietKeTuKhacNhau.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package codeptit;
import java.util.*;
import java.io.*;
/**
*
* @author Administrator
*/
class WordSet{
private TreeSet<String> ts;
public WordSet(String fname) throws FileNotFoundException {
Scanner sc = new Scanner(new File(fname));
this.ts = new TreeSet<>();
while(sc.hasNext()){
String[] s = sc.nextLine().split("\\s+");
for(String i : s){
ts.add(i.toLowerCase());
}
}
}
private String getData(){
String res = "";
for(String i : this.ts){
res += i + "\n";
}
return res;
}
@Override
public String toString() {
return this.getData();
}
}
public class LietKeTuKhacNhau {
public static void main(String[] args) throws IOException {
WordSet ws = new WordSet("VANBAN.in");
System.out.println(ws);
}
}