假设您的列表包含以下元素-
P, W, g, K, H, t, E
因此,区分大小写的顺序意味着,首先,排序的顺序将以大写字母表示,然后是小-
E, H, K, P, W, g, t
以下是我们的数组-
String[] arr = new String[] { "P", "W", "g", "K", "H", "t", "E" };
将上面的数组转换为列表-
List<String>list = Arrays.asList(arr);
现在以区分大小写的顺序对上面的列表进行排序-
Collections.sort(list);
import java.util.Arrays; import java.util.Collections; import java.util.List; public class Demo { public static void main(String[] arg v) throwsException { String[] arr = new String[] { "P", "W", "g", "K", "H", "t", "E" }; List<String>list = Arrays.asList(arr); System.out.println("List = "+list); Collections.sort(list); System.out.println("Case Sensitive Sort = "+list); } }
输出结果
List = [P, W, g, K, H, t, E] Case Sensitive Sort = [E, H, K, P, W, g, t]