TreeSet笔记02
来源:互联网 发布:淘宝new balance正品店 编辑:程序博客网 时间:2024/09/21 08:17
package com.jenthor;import java.util.*;/* * 当元素自身不具备比较性,或者具备的比较性不是所需的、 * 这时就让容器自身具备比较性。 * 定义了比较容器,将比较器对象作为参数传递给TreeSet集合的构造函数 * * 当两种排序都存在时,以比较器为主。 * * 定义一个类,实现Comparator接口,覆盖compare方法。 * * * */public class TreeSetDemo2 {public static void main(String[] args) {TreeSet ts = new TreeSet(new Mycompare());ts.add(new Student("lisi02", 22));ts.add(new Student("lisi007", 20));ts.add(new Student("lisi09", 19));ts.add(new Student("lisi08", 18));ts.add(new Student("lisi08", 18));ts.add(new Student("lisi08", 18));Iterator in = ts.iterator();while (in.hasNext()) {Student s = (Student) in.next();System.out.println(s.getName() + "..." + s.getAge());}}}class Mycompare implements Comparator {public int compare(Object o1, Object o2) {Student s1 = (Student) o1;Student s2 = (Student) o2;int num = s1.getName().compareTo(s2.getName());if (num == 0) { return new Integer(s1.getAge()).compareTo(new Integer(s2.getAge())); }return num;}}
0 0
- TreeSet笔记02
- java TreeSet笔记
- java基础笔记(二--TreeSet)
- TreeSet
- TreeSet
- TreeSet
- TreeSet
- TreeSet
- TreeSet
- TreeSet
- TreeSet
- TreeSet
- TreeSet
- treeset
- TreeSet
- TreeSet
- TreeSet
- TreeSet
- win764 + python2.7.x + opencv 安装
- PL/SQL Developer在64位系统下连接Oracle
- 软件项目管理(CMMI成熟度)实践——之决策分析(1)
- TreeSer笔记
- 如何在 Debian / Ubuntu 服务器上架设 L2TP / IPSec VPN
- TreeSet笔记02
- [Github] fatal: remote error: You can't push to git 解决办法
- HDU 1171 01背包
- TreeSet练习
- NTFS 與 FAT32 格式的選擇 (資料汰舊現已不太適用)
- untiy切换界面窗口代码
- 【Altium Designer/Protel】【精通在于细节】Altium Designer中对未布线的网络进行定位检查,漏线检查【原创】
- 【深入浅出IOS开发】彩票-去除图标的玻璃质感效果
- openstack的系统断电后重启出现虚拟机不能启动的情况