[英]Comparable<> and compareTo method A-Z and Z-A
Is there a way how to sort String
both ways A to Z and Z to A calling same compareTo override method
? 有没有一种方法可以同时对A到Z和Z到A的String
进行排序,从而调用相同的compareTo override method
?
@Override
public int compareTo(Historial o) {
String a = this.getName();
String b = o.getName();
return a.compareTo(b);//This sorts A-Z
}
just replace the names of variables its easy 只需替换变量名称即可
return a.compareTo(b);//This sorts A-Z
return b.compareTo(a);//This sorts Z-A
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.