美文网首页
Java容器总结

Java容器总结

作者: 998584f56259 | 来源:发表于2016-10-26 12:05 被阅读104次

    1.数组将数字与对象联系起来,它保存类型明确地对象,查询对象时,不需要对结果做类型转换。他可以是多维的,可以保存基本类型的数据。但是,数组一旦生成,其容器就不能改变。

    2.Collection保存单一的元素。而Map保存相关联的键值对。有了Java泛型,你就可以指定容器中存放的对象类型,因此你就不会将错误类型的对象放置到容器中,并且在从容器中取元素时,不必进行类型转换。各种Collection和各种Map都可以在你向其中添加更多的元素时,自动调整尺寸。容器不能持有基本类型,但是自动包装机制会仔细地执行基本类型到容器中所持有的包装类型之间的双向转换。

    3.像数组一样,List也建立了数字索引与对象之间的关联,因此,数组和List都是排好序的容器,List能够自动扩充容量。

    4.如果要进行大量的随机访问,就使用ArrayList,如果要经常从表中间插入或删除元素,则应该使用LinkedList。

    5各种Queue以及栈的行为,由LinkedList提供支持。

    6.Map是一种将对象(而非数字)与对象相关联的设计。HashMap设计用来快速访问,而TreeMap保持“键”始终处于排序状态,所以没有HashMap快。LinkedHashMap保持元素插入的顺序,但是也通过散列提供了快速访问的能力。

    7.Set不接受重复元素。HashSet提供最快的查询速度,而TreeSet保持元素处于排序状态。LinkedHashMap以插入顺序保存元素。

    8.新程序中不应该使用过时的Vector、HashTable和Stack。

    9.下面是容器关系图。

    容器关系图.png

    下面是所有Collection和Map的继承、实现关系说明。

    1.Collection接口中的方法
    Collection: [add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray]

    2.Collection继承的接口
    Interfaces in Collection: [Iterable]

    3.Set接口继承Collection接口,没有添加方法
    Set extends Collection, adds: []

    4.Set继承的接口
    Interfaces in Set: [Collection]

    5.HashSet继承自AbstractSet,没有添加方法
    HashSet extends AbstractSet, adds: []

    6.HashSet实现了Set,Cloneable和Serializable接口
    Interfaces in HashSet: [Set, Cloneable, Serializable]

    7.LinkedHashSet继承自HashSet,没有添加方法
    LinkedHashSet extends HashSet, adds: []

    8.LinkedHashSet实现了Set,Cloneable和Serializable接口
    Interfaces in LinkedHashSet: [Set, Cloneable, Serializable]

    9.TreeSet继承自AbstractSet,添加了下面这些方法
    TreeSet extends AbstractSet, adds: [pollLast, navigableHeadSet, descendingIterator, lower, headSet, ceiling, pollFirst, subSet, navigableTailSet, comparator, first, floor, last, navigableSubSet, higher, tailSet]

    10.TreeSet实现了NavigableSet,Cloneable和Serializable接口
    Interfaces in TreeSet: [NavigableSet, Cloneable, Serializable]

    11.List继承自Collection接口,添加了如下方法
    List extends Collection, adds: [listIterator, indexOf, get, subList, set, lastIndexOf]

    12.List实现了ItemSelectable和Accessible接口
    Interfaces in List: [ItemSelectable ,Accessible]

    13.ArrayList继承自AbstractList,添加了如下方法
    ArrayList extends AbstractList, adds: [ensureCapacity, trimToSize]

    14.ArrayList实现了List,RandomAccess,Cloneable和Serializable接口
    Interfaces in ArrayList: [List, RandomAccess, Cloneable, Serializable]

    15.LinkedList继承自AbstractSequentialList,添加了如下方法
    LinkedList extends AbstractSequentialList, adds: [pollLast, offer, descendingIterator, addFirst, peekLast, removeFirst, peekFirst, removeLast, getLast, pollFirst, pop, poll, addLast, removeFirstOccurrence, getFirst, element, peek, offerLast, push, offerFirst, removeLastOccurrence]

    16.LinkedList实现了List,Deque,Cloneable和Serializable接口
    Interfaces in LinkedList: [List, Deque, Cloneable, Serializable]

    17.继承自Collection,添加了如下方法
    Queue extends Collection, adds: [offer, element, peek, poll]

    18.PriorityQueue继承自Queue添加了如下方法
    PriorityQueue extends Queue, adds: [comparator]

    19.PriorityQueue实现了Serializable接口
    Interfaces in PriorityQueue: [Serializable]

    20.Map中有如下方法
    Map: [clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values]

    21.HashMap继承自Map,没有添加方法
    HashMap extends Map, adds: []

    22.HashMap实现了Cloneable和Serializable接口
    Interfaces in HashMap: [Cloneable, Serializable]

    23.LinkedHashMap继承自HashMap没有添加方法
    LinkedHashMap extends HashMap, adds: []

    24.LinkedHashMap实现了Map接口
    Interfaces in LinkedHashMap: [Map]

    25.SortedMap继承自Map,添加了如下方法
    SortedMap extends Map, adds: [subMap, comparator, firstKey, lastKey, headMap, tailMap]

    26.SortedMap实现了Map接口
    Interfaces in SortedMap: [Map]

    27.TreeMap接口继承自Map,添加了如下方法
    TreeMap extends Map, adds: [descendingEntrySet, subMap, pollLastEntry, lastKey, floorEntry, lastEntry, lowerKey, navigableHeadMap, navigableTailMap, descendingKeySet, tailMap, ceilingEntry, higherKey, pollFirstEntry, comparator, firstKey, floorKey, higherEntry, firstEntry, navigableSubMap, headMap, lowerEntry, ceilingKey]

    28.TreeMap实现了NavigableMap,Cloneable,Serializable接口
    Interfaces in TreeMap: [NavigableMap, Cloneable, Serializable]

    相关文章

      网友评论

          本文标题: Java容器总结

          本文链接:https://www.haomeiwen.com/subject/uwmduttx.html