zoukankan      html  css  js  c++  java
  • set

    set是无序的不可重复,要想排序就实现Comparable接口

    package com.cz.test.util.collection.set.sortedset;


    import java.util.SortedSet;
    import java.util.TreeSet;

    public class SortedSetDemo {

    /**
    * @param args
    */
    public static void main(String[] args) {
    SortedSet<Player> players=new TreeSet<Player>();

    Player tom=new Player("Tom", 1, 2, 3);
    Player toms=new Player("Tom", 2, 2, 3);
    Player jack=new Player("jack", 3, 2, 1);
    Player rose=new Player("rose", 3, 1, 1);
    Player jerry=new Player("jerry", 3, 2, 3);
    Player merry=new Player("merry", 1, 1, 2);
    Player chrils=new Player("chrils", 4, 2, 3);

    players.add(chrils);
    players.add(merry);
    players.add(jerry);
    players.add(rose);
    players.add(jack);
    players.add(tom);
    players.add(toms);

    for(Player player:players){
    System.out.println("Player:"+player);
    }

    }

    }

    set取值

    package com.cz.test.util.collection.set.sortedset;

    import java.util.SortedSet;
    import java.util.TreeSet;

    public class TreeSetTest1 {

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    SortedSet set=new TreeSet();
    set.add(2);
    set.add(12);
    set.add(4);
    set.add(-4);
    set.add(27);
    set.add(17);

    //第一个元素
    System.out.println(set.first());
    //最后一个元素
    System.out.println(set.last());
    //返回小于12的集合
    System.out.println(set.headSet(12));
    //返回大于6的集合
    System.out.println(set.tailSet(6));
    //返回大于-3小于5的子集
    System.out.println(set.subSet(-3, 5));

    }

    }

  • 相关阅读:
    MySQL 元数据
    MySQL 复制表
    MySQL 临时表
    MySQL 索引
    MySQL ALTER
    MySQL 事务
    MySQL 正则表达式
    Mysql Join
    Python(数据库之表操作)
    Python知识点复习之__call__
  • 原文地址:https://www.cnblogs.com/javaweb2/p/6241170.html
Copyright © 2011-2022 走看看