【发布时间】:2013-10-31 00:39:03
【问题描述】:
我目前正在从上一个问题中询问的文本文件中读取 200 万行 Java Fastest way to read through text file with 2 million lines
现在我将这些信息存储到 HashMap 中,我想通过 TreeMap 对其进行排序,因为我想使用天花板键。下面的方法对吗?
private HashMap<Integer, String> hMap = new HashMap();
private TreeMap<Integer, String> tMap = new TreeMap<Integer, String>(hMap);
【问题讨论】:
-
Collections.sort(hMap)? ,Collections.sort(hMap,WITH_MY_OWN_COMPARATOR)? -
为什么不直接把它放到
TreeMap中呢?为什么要多走一步? -
hrm...我还是更喜欢用树形图对其进行排序,但就我的代码而言,树形图是空的
-
@suresh atta :
Collections.sort(hMap)不起作用,sort()仅适用于列表