源代码wordRate.java用于计算文章单词词频,如下:
import java.util.*;
import java.io.*;
public class Test{
public static void main(String[] args) throws Exception {
BufferedReader infile =new BufferedReader(new FileReader("source.txt"));//打开一篇文章source.txt
String string;
String words[];//用于存放文章所有单词
String file = null;
while ((string = infile.readLine()) != null) {
file += string;//读出整篇文章,存入String中。
}
file=file.toLowerCase();//所有字母小写化
file=file.replaceAll("[^A-Za-z]"," ");//正则表达式,匹配非英文字符为空格
words=file.split("\\s");//取出单词,空格为单词分界,将分词后的单词存入数组words中
Map hashMap = new HashMap();
for(int i=0;i<words.length;i++){
String key = words[i];
if (hashMap.get(key) != null) {
int value = ((Integer) hashMap.get(key)).intValue();
value++;
hashMap.put(key, new Integer(value));
} else {
hashMap.put(key, new Integer(1));
}
}
//按照单词字母的先后次序输出。
Map treeMap = new TreeMap(hashMap);
Set entrySet = treeMap.entrySet();
Iterator iterator = entrySet.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
}
}
请问:
1、为什么编译会出现如所示警告?
2、Set entrySet = treeMap.entrySet();
Iterator iterator = entrySet.iterator(); 这两句是什么意思?
3、输出时希望按词频大小输出,那如何修改该代码呢?
但编译出现警告,为什么呢?
追答没看见,啊,哦,我直接在eclipse下运行的,是什么警告