我试图将一个简单的对象列表排序很长时间 - 以下是不起作用的,因为其中一个长字符串被推到顶部只是因为它以较低的数字开头.所以我正在寻找一种方法来直接对实际的长值进行排序
当前的obj实现类似于下面的内容.在我正在使用的课程中,我称之为Collections.sort(树);
public class Tree implements Comparable<Tree> {
public String dist; //value is actually Long
public int compareTo(Tree o) {
return this.dist.compareTo(o.dist);
}
}
Run Code Online (Sandbox Code Playgroud)