Java中如何实现中文排序2
发布网友
发布时间:2023-10-17 15:58
我来回答
共1个回答
热心网友
时间:2024-03-06 04:08
public class SortByChinese {
//测试
public static void main(String[] args) {
String[] a1 = {"保定","何子安","于小云","刘帝","刘何保定子安","刘","刘娜","家强","刘博"};
getSortOfChinese(a1);
for (int i = 0; i < a1.length; i++) {
System.out.println(a1[i]);
}
}
/**
*
* @param a String[]
* @return String[]
*/
public static String[] getSortOfChinese(String[] a) {
// Collator 类是用来执行区分语言环境这里使用CHINA
Comparator cmp = Collator.getInstance(java.util.Locale.CHINA);
// JDKz自带对数组进行排序。
Arrays.sort(a, cmp);
return a;
}
}public class SortByChinese {
//测试
public static void main(String[] args) {
String[] a1 = {"小二","张三","李四","王五","刘七"};
getSortOfChinese(a1);
for (int i = 0; i < a1.length; i++) {
System.out.println(a1[i]);
}
}
/**
*
* @param a String[]
* @return String[]
*/
public static String[] getSortOfChinese(String[] a) {
// Collator 类是用来执行区分语言环境这里使用CHINA
Comparator cmp = Collator.getInstance(java.util.Locale.CHINA);
// Arrays工具类对数组进行排序。
Arrays.sort(a, cmp);
return a;
}
}
试试对你的问题是否有用
热心网友
时间:2024-03-06 04:08
public class SortByChinese {
//测试
public static void main(String[] args) {
String[] a1 = {"保定","何子安","于小云","刘帝","刘何保定子安","刘","刘娜","家强","刘博"};
getSortOfChinese(a1);
for (int i = 0; i < a1.length; i++) {
System.out.println(a1[i]);
}
}
/**
*
* @param a String[]
* @return String[]
*/
public static String[] getSortOfChinese(String[] a) {
// Collator 类是用来执行区分语言环境这里使用CHINA
Comparator cmp = Collator.getInstance(java.util.Locale.CHINA);
// JDKz自带对数组进行排序。
Arrays.sort(a, cmp);
return a;
}
}public class SortByChinese {
//测试
public static void main(String[] args) {
String[] a1 = {"小二","张三","李四","王五","刘七"};
getSortOfChinese(a1);
for (int i = 0; i < a1.length; i++) {
System.out.println(a1[i]);
}
}
/**
*
* @param a String[]
* @return String[]
*/
public static String[] getSortOfChinese(String[] a) {
// Collator 类是用来执行区分语言环境这里使用CHINA
Comparator cmp = Collator.getInstance(java.util.Locale.CHINA);
// Arrays工具类对数组进行排序。
Arrays.sort(a, cmp);
return a;
}
}
试试对你的问题是否有用