Java如何在大写字符串之前对小写进行排序 [英] Java how to sort lowercase before uppercase strings

查看:229
本文介绍了Java如何在大写字符串之前对小写进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望文件按其abs路径名排序,但我希望小写字母在大写之前排序。示例:假设我有4个文件:

I want the files to be ordered by their abs path name, but I want the lowercase to be sorted before the uppercase. Example: Let's say I got 4 files:

files2.add("b");
files2.add("A");
files2.add("a");
files2.add("B");

此代码的订单为:[A,B,a,b]
I希望它是:[a,A,b,B]

the order with this code is: [A, B, a, b] I want it to be: [a, A, b, B]

import java.io.File;
import java.util.*;

public class Abs {

    public ArrayList<File> getOrder(ArrayList<File> files) {
        Collections.sort(files, new Comparator<File>() {
            public int compare(File file1, File file2) {
                return file1.getAbsolutePath().compareTo(file2.getAbsolutePath());
            }
        });
        return files;
    }

}


推荐答案

检查 Collat​​or类

你必须仔细阅读这些常量的含义,但其中一个应该可以让你在大写字母之前加上小写字母。

You'll have to read carefully what those constants mean, but one of them should make it possible for you to put lowercase letters before the upper-case letters.

这篇关于Java如何在大写字符串之前对小写进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆