2020.02.26 TreeMap集合

package com.guoyun.bean;

import java.sql.Time;

/** * ClassName: * Function:  ADD FUNCTION * Reason:   ADD REASON * * @author * @Date * @since Ver 1.1 */public class TimeBean implements Comparable<TimeBean>{    //年    public int year;    //描述信息    public String desc;

    @Override    public int compareTo(TimeBean o) {        //升序        return year-o.year;    }}*********************************************************************
package com.guoyun.view;

import com.guoyun.bean.TimeBean;

import java.io.Serializable;import java.util.*;

/** * ClassName: * Function:  ADD FUNCTION * Reason:   ADD REASON * * @author * @Date * @since Ver 1.1 */public class MainView {    public static void main(String[] args) {        TreeMap<Integer,String> map1=new TreeMap<>();        AbstractMap<Integer,String> map2=new TreeMap<>();        Map<Integer,String> map3=new TreeMap<>();        NavigableMap<Integer,String> map4=new TreeMap<>();        SortedMap<Integer,String> map5=new TreeMap<>();        Cloneable map6=new TreeMap<>();        Serializable map7=new TreeMap<>();        map3.put(1,"一个不知名上单");        map3.put(2,"一个不知名打野");        map3.put(3,"一个不知名中单");        map3.put(4,"一个不知名AD");        map3.put(5,"一个不知名辅助");//        System.out.println(map3.get(5));        Set<Integer> set=map3.keySet();        //String和包装类实现自动排序        for (Integer i:set             ) {//            System.out.println(i+"\t"+map3.get(i));        }        Map<TimeBean,String> map8=new TreeMap<>(new MyComparator());        TimeBean t1=new TimeBean();        t1.year=1999;        t1.desc="Birthday";        TimeBean t2=new TimeBean();        t2.year=2000;        t2.desc="After";        TimeBean t3=new TimeBean();        t3.year=1998;        t3.desc="Your";        map8.put(t1,"aojiedechushengriqi");        map8.put(t2,"aojietayisuile");        map8.put(t3,"mourendeshengri");        Set<Map.Entry<TimeBean,String>> set1=map8.entrySet();        for (Iterator<Map.Entry<TimeBean, String>> iterator = set1.iterator(); iterator.hasNext(); ) {            Map.Entry<TimeBean, String> next =  iterator.next();            System.out.println(next.getKey().year+"\t"+next.getValue());        }

    }}****************************************************
package com.guoyun.view;

import com.guoyun.bean.TimeBean;

import java.util.Comparator;

/** * ClassName: * Function:  ADD FUNCTION * Reason:   ADD REASON * * @author * @Date * @since Ver 1.1 */public class MyComparator implements Comparator<TimeBean> {    @Override    public int compare(TimeBean o1, TimeBean o2) {        return o1.year-o2.year;    }}

原文地址:https://www.cnblogs.com/aojie/p/12369342.html

时间: 2024-08-30 15:10:20

2020.02.26 TreeMap集合的相关文章

JAVA中TreeMap集合筛选字母及每一个字符出现的次数

利用TreeMap对字符串进行排序 题目要求: 给出一个字符串:fjdjskgfhbsjkgjnsrgnaHNGKEURHGASLGNw5y74236720573. 要求: 化成字符串a(字符的个数)b()c()... 区分大小写 只读取字母 直接上代码: import java.util.Map; import java.util.Set; import java.util.TreeMap; ? /** * @Author caozy * @Date 2020/1/10 18:18 * @Ve

学习进度2020.02.02

学习进度2020.02.02 View与ViewGroup的概念 学习地址: https://www.runoob.com/w3cnote/android-tutorial-view-viewgroup-intro.html 在Android APP中,所有的用户界面元素都是由View和ViewGroup的对象构成的.View是绘制在屏幕上的用户能与之交互的一个对象.而ViewGroup则是一个用于存放其他View(和ViewGroup)对象的布局容器! Android为我们提供了一个View和

TreeMap集合如何按照Value进行排序

------- android培训.java培训.期待与您交流! ---------- 我们知道,TreeMap集合是按照Key进行排序的,如何按照Value进行排序呢?现在有一个TreeMap集合 键值分别为Man类和Woman类,他们的compareTo()方法都是按照年龄排序,现在我模拟了TreeMap按照Value进行排序的方法. 算法: 1.遍历原TreeMap集合,创建个新的TreeMap集合 2.将原TreeMap集合的键值对互换,存入新的TreeMap集合 (此时,新TreeMa

TreeMap集合遍历学习

/** A:案例演示 TreeMap集合键是Student值是String的案例*/ TreeMap<Student, String> tm = new TreeMap<>(new Comparator<Student>() { @Override public int compare(Student s1, Student s2) { int num = s1.getName().compareTo(s2.getName()); //按照姓名比较 return num

学习进度2020.02.01

学习进度2020.02.01 https://www.runoob.com/w3cnote/android-tutorial-eclipse-adt-sdk-app.html 学习使用Eclipse + ADT + SDK开发Android APP 熟悉了该平台的环境,并简单使用此平台开发了一个简单的APP 原文地址:https://www.cnblogs.com/liurx/p/12250722.html

学习进度2020.02.03

学习进度2020.02.03 https://www.runoob.com/w3cnote/android-tutorial-linearlayout.html https://www.runoob.com/w3cnote/android-tutorial-relativelayout.html 今天学习下Android中的布局,Android中有六大布局,分别是: LinearLayout(线性布局),RelativeLayout(相对布局),TableLayout(表格布局) FrameLa

毕设进度2020.02.04

毕设进度2020.02.04 今天基本上将所有自己现在想到的数据库的表建立完成了. 用户(基本不算) 团组织信息表: 图书表: 原文地址:https://www.cnblogs.com/liurx/p/12261863.html

毕设进度2020.02.05

毕设进度2020.02.05 继续建立数据库和基础代码: 新闻数据库 政策数据库 原文地址:https://www.cnblogs.com/liurx/p/12267248.html

毕设进度2020.02.07

毕设进度2020.02.07 原文地址:https://www.cnblogs.com/liurx/p/12275066.html