Java putting Hashmap into Treemap(Java将Hashmap放入Treemap)
问题描述
我目前正在从上一个问题中询问的文本文件中读取 200 万行Java 读取文本文件的最快方式200万行
I am currently reading 2 million lines from a textfile as asked in the previous question Java Fastest way to read through text file with 2 million lines
现在我将这些信息存储到 HashMap 中,我想通过 TreeMap 对其进行排序,因为我想使用天花板键.下面的方法对吗?
Now I store these information into HashMap and I want to sort it via TreeMap because I want to use ceilingkey. Is the following method correct?
private HashMap<Integer, String> hMap = new HashMap();
private TreeMap<Integer, String> tMap = new TreeMap<Integer, String>(hMap);
推荐答案
HashMap<Integer, String> hashMap = new HashMap<Integer, String>();
TreeMap<Integer, String> treeMap = new TreeMap<Integer, String>();
treeMap.putAll(hashMap);
无论如何都应该工作.
这篇关于Java将Hashmap放入Treemap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!