Java中HashMap排序和遍历 .
<div class="article_content">HashMap排序1、按照key排序
对于java中Map的排序,有排序Map,比如TreeMap,对于这个Map,首先只能按照键排序,其次再put和remove的时候由于需要排序,性能上会有所牺牲。
这种方案,使用hashmap进行创建和添加,如果需要按照key排序,则可以将该hashmap作为参数传递到new TreeMap(hashmap),则可以完成按照key的排序:
TreeMap treemap = new TreeMap(hashmap);
<div class="dp-highlighter">TreeMap treemap = new TreeMap(hashmap);
页:
[1]