首页 > 编程知识 正文

python字典序排列,java链表字典排序

时间:2023-05-04 22:20:13 阅读:170449 作者:1972

import java.util.Comparator;

import java.util.ArrayList;

import java.util.Collections;

公共类测试器{

publicstaticvoidmain (string [ ] args ) {

ArrayList list=new ArrayList (;

list.add (东湾);

list.add (感到自豪);

list.add (东海湾-岩洞);

list.add (傲来药店);

/*

要使用collections sort (方法)对sort (方法)方法进行排序,必须传递参数。 一个是需要排序的Collection,另一个是Comparator

*/

collections.sort(list,new SpellComparator ) );

for(intI=0; i list.size (; I ) {

system.out.println(list.get(I ) );

}

}

}

//*

*汉字拼音顺序比较器

*/

classspellcomparatorimplementscomparator {

公共输入公司(Object o2,Object o2 ) {

try {

//取得比较对象的汉字代码,转换成字符串

stringS1=newstring(O1.tostring ).GetBytes )、(ISO-8859-1 ) );

stringS2=newstring(O2.tostring ).GetBytes )、(ISO-8859-1 ) );

String类的compareTo ) )方法比较两个对象

returnS1.comPareto(S2;

}catch(exceptione ) {

e .打印任务跟踪(;

}

返回0;

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。