HashMap sort by key


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your 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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.