java结构体排序


import java.util.Arrays;
import java.util.Scanner;


public class aa {
    public static class stu implements Comparable{
        int a;
        int b;
        stu(){}//无参构造
        stu(int a,int b){
            this.a = a;
            this.b = b;
        }
        @Override
        public int compareTo(Object o){
            stu s = (stu) o;
            return a - s.a;
        }
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        stu[] no = new stu[4];
        no[0] = new stu(2,3);
        no[1] = new stu(5,99);
        no[2] = new stu(-43,88);
        no[3] = new stu(66,30);
        Arrays.sort(no);
        for(int i = 0;i < no.length;i++){
            System.out.println(no[i].a);
        }
        return;
    }

}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM