码迷,mamicode.com
首页 > 其他好文 > 详细

【TreeMap】

时间:2019-01-31 13:13:44      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:set   nbsp   ring   print   oid   集合   public   auth   世界   

package com.yjf.esupplier.common.test;

import java.util.Set;
import java.util.TreeMap;

/**
 * @author shusheng
 * @description
 * @Email shusheng@yiji.com
 * @date 2018/12/18 13:46
 */
public class TreeMapDemo {
        //键是红黑树结构,可以保证键的排序和唯一性
    public static void main(String[] args) {
        //创建集合对象
        TreeMap<String,String> tm = new TreeMap<String,String>();

        //添加元素
        tm.put("hello", "你好");
        tm.put("world", "世界");
        tm.put("java", "爪哇");
        tm.put("world", "世界2");
        tm.put("javaee", "你好ee");
        tm.put("aaa", "你好ee");

        //遍历集合
        Set<String> set = tm.keySet();
        for(String key : set){
            String value = tm.get(key);
            System.out.println(key + "---" + value);
        }
    }

}

 

【TreeMap】

标签:set   nbsp   ring   print   oid   集合   public   auth   世界   

原文地址:https://www.cnblogs.com/zuixinxian/p/10341197.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!