java字典排序
❶ 如何对Map进行字典排序java
//根据 Map的key进行字典排序
Map<String, String> parameterMap = new HashMap<String, String>();
List<Map.Entry<String,String>> list = new ArrayList<Map.Entry<String,String>>(parameterMap.entrySet());
Collections.sort(list,new Comparator<Map.Entry<String,String>>() {
//升序排序
public int compare(Entry<String, String> o1,
Entry<String, String> o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
❷ java缂栫▼锛氢粠阌鐩樿緭鍏ュ瓧绗︿覆锛屽苟鎸夊瓧鍏搁‘搴忓掑簭镓揿嵃
importjava.util.ArrayList;
importjava.util.Scanner;
publicclassJudgeString{
publicstaticvoidmain(String[]args){
//鎺ュ弹阌鐩樿緭鍏
Scannerin=newScanner(System.in);
//淇濆瓨杈揿叆鏁版嵁镄凩ist
ArrayList<String>list=newArrayList<String>();
System.out.println("璇疯緭鍏ュ瓧绗︿覆锛岃緭鍏モ渆nd钬濅负缁撴潫锛");
//銮峰彇姣忔¤緭鍏ョ殑瀛楃︿覆
Stringtemp=in.nextLine();
//銮峰彇杈揿叆镄勬墍链夊瓧绗︿覆
while(!temp.equals("end")){
list.add(temp);
temp=in.nextLine();
}
//璋幂敤鎺掑簭鍑芥暟
sort(list);
//杈揿叆缁撴灉
System.out.println("鎺掑簭钖庣殑缁撴灉涓猴细");
for(inti=0;i<list.size();i++){
System.out.println(list.get(i));
}
}
//鎺掑簭鍑芥暟锛埚啋娉★级
publicstaticvoidsort(ArrayList<String>list){
Stringtemp="";
for(inti=0;i<list.size();i++){
for(intj=0;j<list.size()-1;j++){
if(list.get(i).compareToIgnoreCase(list.get(j))>0){
temp=list.get(i);
list.set(i,list.get(j));
list.set(j,temp);
}
}
}
}
}
宸茬粡璋冭瘯杩囦简锛岃偗瀹氲兘杩愯岋纴链変笉镍傚缑鍙浠ラ梾
❸ JAVA按着字典顺序排序
如果同时有 new String[] { "ye", "yel", "yellow" };你的排序是ye,yel,yellow
但是如果new String[] { "yel", "ye", "yellow" };排序就变成 排序后:yel ye yellow
❹ Java怎么按照汉字字典顺序给字符串排序
//按照中文第一个字母派燃弊升序排列的实现x0dx0aimport java.text.Collator; x0dx0aimport java.util.Arrays; x0dx0aimport java.util.Comparator; x0dx0apublic class test { x0dx0a /** x0dx0a * @param args x0dx0a */ x0dx0a public static void main(String[] args) { x0dx0a // TODO Auto-generated method stub x0dx0a Comparator