【发布时间】:2020-06-28 08:02:54
【问题描述】:
我有一个字符串列表。
TagSort-Test-CA-ASSET-ID1_ tag4
TagSort-Test-CA-ASSET-ID13_tag
TagSort-Test-CA-ASSET-ID1_ 6th_tag
TagSort-Test-CA-ASSET-ID1_tag1
TagSort-Test-CA-ASSET-ID1_tag2
TagSort-Test-CA-ASSET-ID1_tag5
当我这样做时
List<String> test = Arrays.asList(
"TagSort-Test-CA-ASSET-ID1_ tag4",
"TagSort-Test-CA-ASSET-ID13_tag",
"TagSort-Test-CA-ASSET-ID1_ 6th_tag",
"TagSort-Test-CA-ASSET-ID1_tag1",
"TagSort-Test-CA-ASSET-ID1_tag2",
"TagSort-Test-CA-ASSET-ID1_tag5");
Collections.sort(test);
System.out.println(test);
输出为[TagSort-Test-CA-ASSET-ID13_tag, TagSort-Test-CA-ASSET-ID1_ 6th_tag, TagSort-Test-CA-ASSET-ID1_ tag4, TagSort-Test-CA-ASSET-ID1_tag1, TagSort-Test-CA-ASSET-ID1_tag2, TagSort-Test-CA-ASSET-ID1_tag5]
我怎样才能得到订单
[TagSort-Test-CA-ASSET-ID13_tag, TagSort-Test-CA-ASSET-ID1_ 6th_tag, TagSort-Test-CA-ASSET-ID1_tag1, TagSort-Test-CA-ASSET-ID1_tag2,TagSort-Test-CA-ASSET-ID1_ tag4, TagSort-Test-CA-ASSET-ID1_tag5]
这是我从 postgres DB 获得的格式。我也需要在 Java 中保持相同的行为。
【问题讨论】:
-
你的尝试是什么?你知道 postgress DB 遵循什么模式吗?
标签: java sorting collections java-8 comparator