• Set集合


    public class UpdateStu implements Comparable<Object>{
    
        String name;
        long id;
        
        public UpdateStu(String name,long id) {
            // TODO Auto-generated constructor stub
            this.id = id;
            this.name = name;
        }
        
        public int compareTo(Object o) {
            UpdateStu upstu = (UpdateStu)o;
            int result = id > upstu.id? 1 : (id == upstu.id? 0 : -1);
            return result;
        }
        
        public String getString() {
            return name;
        }
        public void setString(String name) {
            this.name = name ;
        }
        
        public long getid() {
            return id;
        }
        public void setid(long id) {
            this.id = id;
        }
        
        
        public static void main(String[] args) {
            UpdateStu stu1 = new UpdateStu("李同学", 01011);
            UpdateStu stu2 = new UpdateStu("程同学", 01021);
            UpdateStu stu3 = new UpdateStu("王同学", 01051);
            UpdateStu stu4 = new UpdateStu("马同学", 01012);
            TreeSet<UpdateStu> tree = new TreeSet<>();
            tree.add(stu1);
            tree.add(stu2);
            tree.add(stu3);
            tree.add(stu4);
            Iterator<UpdateStu> it = tree.iterator();
            System.out.println("Set集合中的所有元素");
            while(it.hasNext()){
                UpdateStu stu = (UpdateStu)it.next();
                System.out.println(stu.getid() + " " + stu.getString());
            }
            it = tree.headSet(stu2).iterator();
            System.out.println("截取前面部分的集合");
            while(it.hasNext()){
                UpdateStu stu = (UpdateStu)it.next();
                System.out.println(stu.getid() + " " + stu.getString());
            }
            
            it = tree.subSet(stu2, stu3).iterator();
            System.out.println("截取中间部分的集合");
            while(it.hasNext()){
                UpdateStu stu = (UpdateStu)it.next();
                System.out.println(stu.getid() + " " + stu.getString());
            }
            
            
        }
        
    }
  • 相关阅读:
    [LeetCode#91]Decode Ways
    [LeetCode#130]Surrounded Regions
    [LeetCode#84]Largest Rectangle in Histogram
    [LeetCode#179]Largest Number
    [LeetCode#187]Repeated DNA Sequences
    [LeetCode#200]Number of Islands
    [LeetCode#268]Missing Number
    [LeetCode#44]Wildcard Matching
    [LeetCode#128]Longest Consecutive Sequence
    1如何给devexpress的gridview控件绘制全选按钮
  • 原文地址:https://www.cnblogs.com/dulute/p/10592850.html
Copyright © 2020-2023  润新知