java为一些特殊的字符,数字,字母和空格排序

时间:2014-11-01 10:24:01

标签: java sorting

我需要按以下顺序对地图中提到的符号进行排序。
第一个空白,第二个*,第三个**,第四个小写字母,按字母顺序排列,第五个大写字母按字母顺序排列,第六个数字按升序排列,最后一个()符号

  Map<String, String> symbols = new HashMap<String, String>();
  symbols.put("001","*");
  symbols.put("002","**");
  symbols.put("003"," ");
  symbols.put("004","s");
  symbols.put("005","A");
  symbols.put("006","g");
  symbols.put("007","f");
  symbols.put("008","6");
  symbols.put("009","9");
  symbols.put("0010","()");
  symbols.put("0011","*");
  symbols.put("0012","10");
  symbols.put("0013","Y");
  symbols.put("0014","**");
  symbols.put("0015","()");
  symbols.put("0016","**");
  symbols.put("0017"," ");

为清楚起见:最终的解决方案是LinkedHashMap,其中包含我提到的排序记录。

1 个答案:

答案 0 :(得分:2)

这对你有用吗<​​/ p>

    ` Map<Integer, String> symbols = new HashMap<Integer, String>();
      symbols.put(1,"*");
      symbols.put(2,"**");
      .............`