如题!
在一个有几千行的文本文件里边,可能会有若干行的数据是相同的,现在想要把这里边相同的数据统计出来并打出相同数据的数目,没有相同的数据打印在统计结果的最下方。
请达人帮帮忙!!!
谢谢~~~~~!!!

解决方案 »

  1.   

    使用一个 map 来统计结果。BufferedReader in = new BufferedReader(new FileReader("d:\\a.txt"));String line = null;
    HashMap map = new HashMap;while( (line=in.readLine()) != null )
    {
        if( map.containsKey(line) )
        {
            Integer integer = (Integer)map.get(line);
            map.put(line, new Integer(integer.intValue() + 1);
        }
        else
        {
            map.put(line, new Integer(1));
        }
    }// 最后
    String strs [] = new String(map.size());
    map.keySet().toArray(strs);然后再依次从 map 中取出 Integer 就知道了有没有重复。
      

  2.   

    非常感谢 sswater(水与争锋) !!
    不过 现在出现这个怎么解决?
    Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space