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;
// }
set
最新推荐文章于 2021-06-19 16:00:43 发布