java中map排序(SortedMap的用法)
发布日期:2021-10-03 01:52:05
浏览次数:11
分类:技术文章
本文共 974 字,大约阅读时间需要 3 分钟。
package JavaSenior; import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; /** * HashMap比SortedMap快,非排序的时候用HashMap * @author Administrator */ public class Java_Sortedmap { public static void main(String[] args) { HashMap<String , String> map = new HashMap<String ,String>(); map.put("10", "hello10"); map.put("20", "hello20"); map.put("30", "hello30"); //遍历map for(Entry<String,String> entry: map.entrySet()){ System.out.println("排序之前:"+entry.getKey()+"-->"+entry.getValue()); } System.out.println("======================================================"); SortedMap<String, String> sortMap = new TreeMap<String,String>(map); Set<Entry<String,String>> entry1 =sortMap.entrySet(); Iterator<Entry<String,String>> it = entry1.iterator(); while(it.hasNext()){ Entry<String, String> entry3 = it.next(); System.out.println("排序之后:"+entry3.getKey()+"-->"+entry3.getValue()); } } }转载地址:https://blog.csdn.net/kai402458953/article/details/88340432 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月25日 15时42分04秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
NetBeans配置Xdebug 远程调试PHP
2019-04-27
MediaWiki安装
2019-04-27
Squid安装
2019-04-27
如何查看当前Linux的版本
2019-04-27
Ubuntu安装Nginx
2019-04-27
Ubuntu 下安装thttpd Web服务器
2019-04-27
用thttpd做Web Server
2019-04-27
服务器端开发经验总结 Linux C语言
2019-04-27
将网站程序放在tmpfs下
2019-04-27
使用Nginx的proxy_cache缓存功能取代Squid
2019-04-27
nginx 反向代理,动静态请求分离,proxy_cache缓存及缓存清除
2019-04-27
nginx 的proxy_cache才是王道
2019-04-27
Nginx proxy_cache 使用示例
2019-04-27
Nginx源代码分析 - 日志处理
2019-04-27
使Apache实现gzip压缩
2019-04-27
Memcached在大型网站中应用
2019-04-27
Hadoop简要介绍
2019-04-27
squid中的X-Cache和X-Cache-Lookup的意义
2019-04-27
squid 优化指南
2019-04-27
编程方式刷新Squid缓存服务器的五种方法
2019-04-27