您的位置:首页 > 理论基础 > 数据结构算法

Java常用单线程数据结构比较

2010-07-15 14:01 351 查看
Lists

Type

Random access

Insertions and removals

Multi-threading

Additional Info

Vector<?>

Very good,born for it

Not very good

thread-safe

Direct-subclass : stack

ArrayList<?>
Same as vector

Same as vector

No support,need explicit synchronizing

LinkedList<?>
Costly

Very good,should be the option within the catalog

Not thread-safe

Actually is a doubly-linked list

can be used as

stack, queue, or double-ended queue (deque).

Maps
Type

Storage-based

Time complexity(key locating)

Multi-threading

Additional info

Hasktable<K,V>

Hash

O(1)

Internally synchronized

HashMap<K,V>

Hash

0(1)

Not synchronized

Conceptually the same as hashtable except for the thread-safety

LinkedHashMap<K,V>

Hash

O(1)

Not synchronized

Use the same technique as the hashmap and hashtable classes to store the data. However,it also maintains a running linkedlist that contains all of the keys in the map in a sorted order

IdentityHashMap<K,V>

Hash

O(1)

Not synchronized

Objects are compared based on identity(only if the same instance ),not equality

Weakhashmap<K,V>

Hash

O(1)

Not synchronized
Keys are sorted in weak references

TreeMap<K,V>

Balanced binary tree

O(log2(n))

Not synchronized

Regarding to sorted key order , this is

better at storing large sets of data,since log2(n) grows very slowly as n increases,this size trade-off is often worth the cost.

Sets
Type

Storage-based

Multi-threading

Additional info

Hashset<E>

Hash

Not synchronized

Merely insert a dummy value for each key in the map and hide the face that it is using a map from the user

LinkedHashSet<E>

Hash

Not synchronized

Maintain a linkedlist of the objects in the set,which can significantly decrease the amount of available memory

TreeSet<E>

Binary balanced tree

Not synchronized

Inherit the same benefits and limitations as the TreeMap class

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: