Java编程中如何实现中文排序
在不断的`Java学习中,我们就能发现在很多的时候还是有不少的技巧。下面本站小编为大家整理了关于Java编程中如何实现中文排序的文章,希望对你有所帮助。
第一种情况:
Comparator cmp = nstance(A);
String[] arr = { “张三”, “李四”, “王五”, “刘六” };
(arr, cmp);
for (int i = 0; i 《 th; i++)
tln(arr[i]);
第二种情况:
//
import ationKey;
import ator;
import BasedCollator;
import arator;
public class ComparableBean{
private String name;
public ComparableBean(String name) {
= name;
}
public String getName() {
return name;
}
public void setName(String name) {
= name;
}
}
class ComparableBeanComparator implements Comparator//
{
RuleBasedCollator collator; // you can set your rules for the instance “collator”
public ComparableBeanComparator()
{
collator = (RuleBasedCollator)nstance(A);// try testing various locales
}
public int compare(Object obj1, Object obj2) {
String tempname1 = ((ComparableBean) obj1)。getName();
String tempname2 = ((ComparableBean) obj2)。getName();
CollationKey c1 = ollationKey(tempname1);
CollationKey c2 = ollationKey(tempname2);
// return are(((CollationKey) c1)。getSourceString(),
// ((CollationKey) c2)。getSourceString());
return are(((CollationKey) c2)。getSourceString(),
((CollationKey) c1)。getSourceString());
}
// public int compare(ComparableBean obj1, ComparableBean obj2) {
// String tempname1 = ame();
// String tempname2 = ame();
//
// CollationKey c1 = ollationKey(tempname1);
// CollationKey c2 = ollationKey(tempname2);
// return are(((CollationKey) c1)。getSourceString(),
// ((CollationKey) c2)。getSourceString());
// }
}
//the end of
测试代码:
ComparableBean[] nameContent = { new ComparableBean(“一切从实际出发”),
new ComparableBean(“立于不败之地”), new ComparableBean(“多项式”),
new ComparableBean(“贯彻落实”), new ComparableBean(“密切联系群众”),
new ComparableBean(“四项基本原则”), new ComparableBean(“咬牙切齿”),
new ComparableBean(“恭恭敬敬”), new ComparableBean(“民警”),
new ComparableBean(“经营承包责任制”) };
(nameContent,new ComparableBeanComparator());
for (int i = 0; i 《 th; i++) {
tln(nameContent[i]。getName());
}
-
七种计算机认证考试简介
眼下,各种计算机证书可是宝贝,有了这一纸证书,招聘台前腰板儿都要硬三分。以下是小编为大家介绍七种计算机认证考试,欢迎大家前来了解!全国计算机应用技术证书(NIT)考试它是教育部考试中心推出的以全体公民为对象的非学历性的计算机考试。这个考试注重培养学员使用...
-
计算机二级office考试上机必知内容
成为一名程序员首先要掌握一种主流编程语言,学习任意一种主流的编程语言,例如C++语言。下面是小编整理的.关于计算机二级office考试上机必知内容,欢迎大家参考!一、考试内容要求:1、掌握计算机基础知识及计算机系统组成2、了解信息安全的基本知识、掌握计算机病毒...
-
2017年计算机二级office题库选择题
2017年3月计算机等级考试定于3月25日-28日举行,下面是小编整理的一些关于计算机二级office题库选择题,希望对各位考生有所帮助!1.程序流程图中带有箭头的线段表示的是()。A.图元关系B.数据流C.控制流D.调用关系答案:C【解析】在数据流图中,用标有名字的箭头表示数...
-
2016年《构建H3C数据中心网络》模拟试题及答案
1.数据中心分类中,按TIA-942可以分成()级,按国标GB50174可以分成()级?A、3,3B、3,4C、4,3D、4,4正确答案:C2.数据中心的互联网出口带宽优化主要包括如下哪些方面?(选择一项或多项)A、恶意流量过滤B、专线备份管理C、不同ISP用户就近选择相应服务器D、内网用户就近选择...