标签:png arrays array ack inf else pareto blank 自定义类
摘抄自 b站尚硅谷JAVA教程
通过实现 Comparable 或者 Camparator来完成
package com.LearnJava.Compare; public class myClass implements Comparable{ private String name; private double price; public myClass(String name, double price) { this.name = name; this.price = price; } @Override public String toString() { return "myClass{" + "name=‘" + name + ‘\‘‘ + ", price=" + price + ‘}‘; } @Override public int compareTo(Object o) { myClass m = (myClass) o; if(this.price!= m.price){ return Double.compare(this.price,((myClass) o).price); }else { return -this.name.compareTo(m.name); } } }
Arrays.sort(m, new Comparator<myClass>() { @Override public int compare(myClass o1, myClass o2) { return Double.compare(o1.getPrice(),o2.getPrice()); } });
标签:png arrays array ack inf else pareto blank 自定义类
原文地址:https://www.cnblogs.com/superxuezhazha/p/12304436.html