Java如何在大写字符串之前对小写进行排序

编程入门 行业动态 更新时间:2024-10-27 08:33:07
本文介绍了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()pareTo(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如何在大写字符串之前对小写进行排序

本文发布于:2023-11-12 11:33:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581387.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   如何在   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!