为什么不能 排序
public class WordCount {
private Map m = new HashMap();
private String str = " ";
private Pattern pattern;
public WordCount(String filename) throws Exception {
BufferedReader in = new BufferedReader(new FileReader(
new File(filename)));
String s;
String[] strAry = new String[((int) new File(filename).length()) / 2];
while ((s = in.readLine()) != null)
str += s + " ";
Matcher match = Pattern.compile( "[a-zA-Z]+ ").matcher(str);
for (int i = 0;match.find();i++)
strAry[i] = match.group();
Arrays.sort(strAry);
//这里排序会抛出异常,无法排序,为什么?
}
------解决方案--------------------抛什么异常了? 如果是no pointer应该是因为你的数组strAry里边有些string是null
------解决方案--------------------数组容量过大
有许多空值
把数组容量改了
就对了