android数据存放map_android开发之-数据存储Map、HashMap、Hashtable、concurenthashmap区别...

选择一个map进行软件基础数据初始化操作,要求第一次初始化后,不修改数据,可能会出现静态类被回收,然后在进行初始化操作?

1.Map :接口

/*** A {@codeMap} is a data structure consisting of a set of keys and values

* in which each key is mapped to a single value. The class of the objects

* used as keys is declared when the {@codeMap} is declared, as is the

* class of the corresponding values.

*

* A {@codeMap} provides helper methods to iterate through all of the

* keys contained in it, as well as various methods to access and update

* the key/value pairs.*/

一个map是由一组键和值组成的数据结构 ,其中每个键映射到一个单一的值。当Map被声明后,values的值将被作为key 的关联值被声明

Map提供帮助方法来遍历所有它的包含键值,以及各种方法来访问和更新键/值对。

ps:Map提供key、values形式的声明,public interface Map{},map是一个接口,不能直接使用。

2.hashMap

/*** HashMap is an implementation of {@linkMap}. All optional operations are supported.

*

*

All elements are permitted as keys or values, including null.

*

*

Note that the iteration order for HashMap is non-deterministic. If you want

* deterministic iteration, use {@linkLinkedHashMap}.

*

*

Note: the implementation of {@codeHashMap} is not synchronized.

* If one thread of several threads accessing an instance modifies the map

* structurally, access to the map needs to be synchronized. A structural

* modification is an operation that adds or removes an entry. Changes in

* the value of an entry are not structural changes.

*

*

The {@codeIterator} created by calling the {@codeiterator} method

* may throw a {@codeConcurrentModificationException} if the map is structurally

* changed while an iterator is used to iterate over the elements. Only the

* {@coderemove} method that is provided by the iterator allows for removal of

* elements during iteration. It is not possible to guarantee that this

* mechanism works in all cases of unsynchronized concurrent modification. It

* should only be used for debugging purposes.

*

*@param the type of keys maintained by this map

*@param the type of mapped values*/

HashMap继承了map,实现了map的所有方法。key和value允许使用全部的元素,包括null

注意遍历hashMap是随机的,如果你想定义遍历顺序,请使用LinkedHashMap。

注意:HashMap实现是不同步的。如果多个线程的一个线程访问一个实例map,修改了该map结构,使用的map需要同步。

结构上的修改是指添加或删除一个节点的操作。改变一个map的值不是结构上的变化。

通过Iterator创建并遍历hashMap时,如果使用iterator遍历map的元素,map的结构被修改时,此时可能抛ConcurrentMod

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值