HashMap, Hashtable, LinkedHashMap and TreeMap are all classes
implementing the Map interface. All of them will have keys and values.
The keys are unique. To find out whether the keys are same, they make
use of the equals() method.
So, let us look at each one of them:
HashMap
HashMap is not sorted or ordered. If you just need a Map, and you don’t care about the order of the elements while iterating through it, you can use a HashMap. That keeps it simple. The values can be null. But the key should ne unique, so you can have one null value for key. (Allows only one null key).
Hashtable
Hashtable is almost the same as HashMap. The main differences are:
1. Hashtable does not let you have null value for key.
2. The key methods of Hashtable are synchronized. So, they may take a longer time to execute, compared to HashMap’s methods.
LinkedHashMap
LinkedHashMap will keep the order in which the elements are inserted into it. If you will be adding and removing elements a lot, it will be better to use HashMap, because LinkedHashMap will be slower to do those operations. But, you can iterate faster using LinkedHashMap. So, if you will be iterating heavily, it may be a good idea to use this.
TreeMap
TreeMap is a sorted Map and will be sorted by the natural order of the elements. If you want, you can define a custom sort order by means of a Comparator passed to the constructor. So, when you need a custom sort order, it is clear which class you should be using!
相关推荐
主要介绍了在Java 8中将List转换为Map对象方法,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
Java代码Map转Object对象
java中将数据库中数据直接赋值给Map对象,目的是为了方便取值,这种方式需要用到spring框架
Java 对象属性map排序示例
使用 Core Java JDK1.8,将Map对象转换成Java实体对象的工具类完整代码。仅供交流学习。
js Map对象封装 和 java 的使用方法一样.
将java对象list或者map转json数据不需要第三方包,直接使用就可以了,如果你传入的数据不确定是map类型还是list类型,那么自己处理一下就可以了(判断下类型,传入参数改为object)。 如果是json数据转成java对象list...
javascript仿java的map对象
如何用Map对象创建Set对象Java开发Java经验技巧共3页.pdf.zip
<FONT color=#0000ff>//方法一: 用entrySet() Iterator it = emails.entrySet().iterator();... Map.Entry m=(Map.Entry)it.next(); logger.info("email-" + m.getKey() + ":" + m.getValue()); }
通过引用【opevcsv】依赖,逐行读取数据 并转为Map,Object>格式,后续可以通过BeanUtil.MaptoBean()方法将map转为你需要的bean对象; csv文件必须带表头,bean对象命名符合驼峰格式; 通过此方法可以快速的将文件...
json格式与java类对象相互转换。json格式转换成java类对象,List,Map。类对象转换成json。
java.util 中的集合类包含 Java 中某些最常用的类。 最常用的集合类是 List 和 Map。 List 的具体实现包括 ArrayList 和 Vector,它们是可变大小的列表,比较适合构建、存储和操作任何类型对象的元素列表。 List ...
js终于有了自己的Map了,类似与java的Map对象。此文件是源代码,亲测有类似于java的Map对象的类似方法:put(key,value)、get(key)、keys()、values()、size()、isEmpty()、remove(key)、clear()、element(index)、...
Java代码Object对象转Map
// map对象容器里面储存的元素是(key,value)形式的键值对,比如(a,1)(b,20)(c,55) // key不可以重复,value可以重复 // 常用的map接口的实现类有HashMap,LinkedHashMap和TreeMap // HashMap不保证集合中元素的顺序,...
java.util 中的集合类包含 Java 中某些最常用的类。 最常用的集合类是 List 和 Map。...本例将着重介绍核心 Java 发行套件中附带的 Map,同时还将介绍如何采用或实现更适用于您应用程序特定数据的专用 Map
Java中 List《map》把里面map中某个key相同记录的其他key 的 value 合并 Java中 List《map》把里面map中某个key相同记录的其他key 的 value 合并
有Map的四种遍历方式。Java怎样调用存储过程。九大内置对象。
Java CopyUtil工具类,可以进行对象的深copy,比如:对象里面包含对象,对象里面包含Map,List,Set...等复杂类型的属性都可以copy,copy后的对象与原有对象没有联系,即改变原有对象内容,不会改变copy后的对象里面的...