What is the difference between Lists, ArrayLists, Maps, Hashmaps, Collections etc..?

后端 未结 10 1747
-上瘾入骨i
-上瘾入骨i 2021-01-30 01:38

I\'ve been using HashMaps since I started programming again in Java without really understanding these Collections thing.

Honestly I am not really sure if using HashMaps

10条回答
  •  北恋
    北恋 (楼主)
    2021-01-30 02:34

    List — An ordered collection of elements that allows duplicate entries

    Concrete Classes:

    ArrayList — Standard resizable list.
    LinkedList — Can easily add/remove from beginning or end.
    Vector — Older thread-safe version of ArrayList.
    Stack — Older last-in, first-out class.


    Set — Does not allow duplicates

    Concrete Classes:

    HashSet—Uses hashcode() to find unordered elements.
    TreeSet—Sorted and navigable. Does not allow null values.


    Queue — Orders elements for processing

    Concrete Classes:

    LinkedList — Can easily add/remove from beginning or end.
    ArrayDeque—First-in, first-out or last-in, first-out. Does not allow null values.


    Map — Maps unique keys to values

    Concrete Classes:

    HashMap — Uses hashcode() to find keys.
    TreeMap — Sorted map. Does not allow null keys.
    Hashtable — Older version of hashmap. Does not allow null keys or values.

提交回复
热议问题