package demo;

import java.io.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* @author yeqv
* @program A2
* @Classname A3
* @Date 2022/1/19 20:55
* @Email w16638771062@163.com
*/
public class A3 {

public static void main(String[] args) {
Set<String> set = new HashSet<>();
List<String> list = new ArrayList<>();
File file = new File("D:\\jdk.txt");
Pattern pattern = Pattern.compile("\s[a-zA-Z]+\s");
String len;
try {
BufferedReader buff = new BufferedReader(new FileReader(file));
while ((len = buff.readLine()) != null) {
Matcher matcher = pattern.matcher(len);
while (matcher.find()) {
set.add(matcher.group());
list.add(matcher.group());
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
int b = 1;
for (String s : set) {
int a = 0;
for (String s1 : list) {
if (s.equals(s1)) {
a += 1;
}
}
System.out.printf("%d单词:%s 数量:%d%n", b, s, a);
b += 1;
}

}

}