相关疑难解决方法(0)

如何对具有字符串和整数组合数据(例如1094天,1092天,994天,973天)的列表执行排序操作

我有一个值994天,973天,1094天,1092天,189天,184天的列表,并想按升序执行排序。因此,当使用Collections.sort()时,其排序顺序不正确

  List<String>  list = new LinkedList<String>();
   list.add("994 days");
   list.add("973 days");
   list.add("1094 days");
   list.add("1092 days");
   list.add("189 days");
   list.add("184 days");
Run Code Online (Sandbox Code Playgroud)

我想按升序排序,所以我的输出必须是:184天,189天,973天,994天,1092天,1094天

java

1
推荐指数
1
解决办法
51
查看次数

按字母顺序对java中的字符串列表进行排序

我有一个包含这种格式的字符串的列表:

List<String> ids = new ArrayList<>();

ids.add("B-7");
ids.add("B-5");
ids.add("A-3");
ids.add("B-8");
ids.add("B-1");
ids.add("B-6");
ids.add("B-2");
ids.add("B-3");
ids.add("B-10");
ids.add("A-1");
ids.add("B-4");
ids.add("B-9");
ids.add("A-2");
Run Code Online (Sandbox Code Playgroud)

我需要对其进行排序以获得此输出,(遍历列表):

A-1
A-2
A-3
B-1
B-2
B-3
B-4
B-5
B-6
B-7
B-8
B-9
B-10
Run Code Online (Sandbox Code Playgroud)

我在用:

List<String> sortedIds = ids.stream().sorted().collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)

但相反,我的输出:

A-1
A-2
A-3
B-1
B-10   -- Error
B-2
B-3
B-4
B-5
B-6
B-7
B-8
B-9
Run Code Online (Sandbox Code Playgroud)

java sorting list

1
推荐指数
1
解决办法
100
查看次数

如何在c ++中对可能没有填充数字的文件名进行排序?

我需要对可以有一个共同根目录的文件名进行排序,然后是不一致填充的数字; 一个示例是在Windows中重命名多个文件时获得的示例.

filenamea(1).txt filenamea(2).txt ... filenamea(10).txt ... filenamea(100).txt ... filenameb.txt ... filenamec(1).txt filenamec(2).文本

等等...

c++ sorting filenames

0
推荐指数
1
解决办法
2552
查看次数

Sorting an ArrayList of numbers, in numerical order

I have a String list of numbers (they can be an int list, just need to turn it into an array list to return), this numbers can be from a range, for example from 1 to 25.

I tried sorting them using Collections.sort(numbersList); but it sorts them in a weird way. For example this is the current sorting:

1
10
11
..
2
20
21
..
Run Code Online (Sandbox Code Playgroud)

What I really want is for it to be sorted in a numerical order, …

java sorting arraylist

-1
推荐指数
1
解决办法
75
查看次数

标签 统计

java ×3

sorting ×3

arraylist ×1

c++ ×1

filenames ×1

list ×1