小编Pic*_*ure的帖子

在列表中排序不同类型的字符串

我有一个包含AA0 AA5 BB2 BB9 AA1 BB13 AA7 AA2不按顺序的字符串列表.我想要的是两个单独的类别,如AA0 AA1 AA2 AA5 AA7 BB2 BB9 BB13我可以这样做?

我试图myList.stream().sorted(mySorter).foreach(...);在那里mySorter象下面这样:

  private final Comparator<String> mySorter= ( o1, o2 ) -> {
  try
  {
     final int first = Integer.parseInt( o1.substring( 2, o1.length() ) );
     final int second = Integer.parseInt( o2.substring( 2, o2.length() ) );
     System.out.println( o1 + " -> " + first + " " + o2 + " -> " + second );
     if ( o1.contains( "AA" …
Run Code Online (Sandbox Code Playgroud)

java sorting string string-comparison java-stream

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

标签 统计

java ×1

java-stream ×1

sorting ×1

string ×1

string-comparison ×1