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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java将Hashmap放入Treemap


基础教程推荐
- 存储 20 位数字的数据类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13