Descending Sort with underscore in string

  Kiến thức lập trình

I’m trying to perform a descending sort on a column that contains an underscore within the string. This is my descending sort method.

protected void validateDescendingOrder(Integer column) {
    // create a column list
    List<String> columnList = getColumnList(column);

    // create a new list and sort
    List<String> sortedcolumnList = new ArrayList<String>();
    Collections.sort(sortedcolumnList, new Comparator<String>() {
    public int compare(String o1, String o2) {
        if (o1.contains("_") && o2.contains("_")) {
            return compare(o1.substring(1), o2.substring(1));

        if (o1.contains("_")) {
            return 1;
        if (o2.contains("_")) {
            return -1;

        return o1.compareTo(o2);

I’m expecting my sort to return
Test_jenn, Test_Community, TestRelease, TestCom1, test1, but instead it’s returning
TestRelease, TestCom1, Test_jenn, Test_Community, test1

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website