标签:自定义 sys acea ati ace val out lis 定义
// 1.8
public class text {
public static void main(String[] args) {
String s1 = "哈哈哈11,呵呵呵22,嘿嘿33,四44";
List<String> collect = Arrays.stream(s1.split(",")).sorted((str2, str1) -> {
Integer int1 = Integer.valueOf(str1.replaceAll("[^0-9]", ""));
Integer int2 = Integer.valueOf(str2.replaceAll("[^0-9]", ""));
return int1 - int2;
}).map(str -> str.replaceAll("[0-9]", "")) .collect(Collectors.toList());
System.out.println(collect);
}
}
//1.7
public class text {
public static void main(String[] args) {
String s1 = "哈哈哈11,呵呵呵22,嘿嘿33,四44";
List<String> strings = Arrays.asList(s1.split(","));
Collections.sort(strings, new Comparator<String>() {
@Override
public int compare(String str1, String str2) {
return Integer.valueOf(str1.replaceAll("[^0-9]", "")) - Integer.valueOf(str2.replaceAll("[^0-9]", ""));
}
});
System.out.println(strings);
}
}
String字符串排序1.8 lamda表达式以及1.7自定义排序
标签:自定义 sys acea ati ace val out lis 定义
原文地址:https://www.cnblogs.com/jabez1992/p/10795113.html