在Java 8中以不区分大小写的方式对字符串值进行排序
如何在下面按不区分大小写的顺序对字符串值进行排序?
List<Employee> listofEmployees = Arrays.asList( new Employee(1, "aaa", Arrays.asList(123, 345, 678)),
new Employee(1, "bbb", Arrays.asList(91011, 121314, 1516117)),
new Employee(2, "ccc", Arrays.asList(181920, 212223, 242526)),
new Employee(3, "ddd", Arrays.asList(272829, 303132, 333435)),
new Employee(4, "BBB", Arrays.asList(29, 332, 33))
);
我这样写:
listofEmployees.stream().sorted(Comparator.comparing(Employee::getName).reversed()) .forEach(s -> System.out.println(s.getName()));
如何在此处传递不区分大小写的字符串选项?
回答:
试试这个
Comparator.comparing(Employee::getName, String.CASE_INSENSITIVE_ORDER)
以上是 在Java 8中以不区分大小写的方式对字符串值进行排序 的全部内容, 来源链接: utcz.com/qa/428055.html