set

import com.mysql.cj.jdbc.result.UpdatableResultSet;
import com.sun.jmx.snmp.internal.SnmpSubSystem;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;

public class Example {
    public static  void main(String[] args) {
        UpDateStu stu1=new UpDateStu("李同学",01011);
        UpDateStu stu2=new UpDateStu("王同学",01051);
        UpDateStu stu3=new UpDateStu("马同学",01012);
        TreeSet<UpDateStu>tree=new TreeSet<>();
        tree.add(stu1);
        tree.add(stu2);
        tree.add(stu3);
        Iterator<UpDateStu>iterator=tree.iterator();
        while (iterator.hasNext()){
            UpDateStu stu=(UpDateStu)iterator.next();
            System.out.println(stu.getId()+":"+stu.getName());
        }
    }
}

class UpDateStu implements  Comparable{
   String name;
   long id;
   public  UpDateStu(String name,long id){
       this.name=name;
       this.id=id;
   }
    @Override
    public int compareTo(Object o) {
        UpDateStu upDateStu = (UpDateStu) o;
        int result = id > upDateStu.id ? 1 : (id == upDateStu.id ? 0 : -1);
        return result;
    }
    public  String getName(){
       return name;
    }
    public  void setName(String name){
       this.name=name;
    }
    public  long getId(){
       return id;
    }
    public  void setId(long id){
       this.id=id;
    }
}




















//class MyImageIcon extends JFrame {
//
//    public MyImageIcon() {
//        Container container = new Container();
//        container = getContentPane();
//        JLabel jLabel = new JLabel("这是你java的妈", JLabel.CENTER);
//        URL url = MyImageIcon.class.getResource("timg (1).jpg");
//        Icon icon = new ImageIcon(url);
//        jLabel.setIcon(icon);
//        jLabel.setHorizontalAlignment(SwingConstants.CENTER);
//        jLabel.setOpaque(true);
//        container.add(jLabel);
//        setSize(25, 100);
//        setVisible(true);
//        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
//    }
//
//}

//class  MyFrame extends  JFrame {
//    public MyFrame() {
//        JFrame jFrame = new JFrame("憨批");
//        Container container = jFrame.getContentPane();
//        JLabel jLabel = new JLabel("这是你妈");
//        jLabel.setHorizontalAlignment(SwingConstants.CENTER);
//        JButton jButton = new JButton("这是按钮");
//        jButton.setBounds(10, 10, 200, 21);
//        jButton.addActionListener(new ActionListener() {
//            @Override
//            public void actionPerformed(ActionEvent e) {
//                new MyDialog(MyFrame.this).setVisible(true);
//            }
//        });
//        container.add(jLabel);
//        container.add(jButton);
//        container.setBackground(Color.RED);
//
//        jFrame.setVisible(true);
//        jFrame.setSize(100, 200);
//        jFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
//    }
//}
//class MyDialog extends JDialog {
//    public MyDialog(MyFrame frame) {
//        super(frame, "第一个", true);
//        Container container = getContentPane();
//        container.add(new JLabel("太惨了"));
//        setBounds(120, 120, 100, 100);
//    }
//
//}
//class  DrawIcon implements  Icon{
//    int width,high;
//    public  DrawIcon(int width,int high){
//        this.high=high;
//        this.width=width;
//    }
//    @Override
//    public void paintIcon(Component c, Graphics g, int x, int y) {
//         g.fillOval(x,y,width,high);
//    }
//
//    @Override
//    public int getIconWidth() {
//        return this.width;
//    }
//
//    @Override
//    public int getIconHeight() {
//        return this.high;
//    }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值