java分割加排序

测试类

public class Test_Student02 {
    public static void main(String[] args) {
        List<Student02> list = new ArrayList<>();
        String s = "张三-男-18|李四-男-19|王五-女-20|赵六-女-17";
        String[] split = s.split("[|]");
        for (String s1 : split) {
            String[] split1 = s1.split("[-]");
            list.add(new Student02(split1[0],split1[1],Integer.parseInt(split1[2])));



        }
        Collections.sort(list, new Comparator<Student02>() {
            @Override
            public int compare(Student02 o1, Student02 o2) {
                int a = o1.getFs()-o2.getFs();
                return a;
            }
        });
        for (Student02 student02 : list) {
            System.out.println(student02);
        }
    }

实体类

private String name;
   private String xb;
   private int fs;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getXb() {
        return xb;
    }

    public void setXb(String xb) {
        this.xb = xb;
    }

    public int getFs() {
        return fs;
    }

    public void setFs(int fs) {
        this.fs = fs;
    }

    public Student02() {
    }

    public Student02(String name, String xb, int fs) {
        this.name = name;
        this.xb = xb;
        this.fs = fs;
    }

    @Override
    public String toString() {
        return "Student02{" +
                "name='" + name + '\'' +
                ", xb='" + xb + '\'' +
                ", fs=" + fs +
                '}';
    }

运行结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值