Posted By

multani on 10/20/08


Tagged

javahashmap


Versions (?)

HashMap sort by key


 / Published in: Java
 

URL: http://levi.bloghome.cn/posts/120920.html

  1. HashMap按key排序
  2. HashMap map = new HashMap();
  3. map.put("0201", "0201");
  4. map.put("01", "01");
  5. map.put("0304", "0304");
  6. map.put("0101", "0101");
  7.  
  8. Object[] key = map.keySet().toArray();
  9. Arrays.sort(key);
  10.  
  11. for (int i = 0; i < key.length; i++) {
  12. System.out.println(map.get(key[i]));
  13. }

Report this snippet  

You need to login to post a comment.