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

后端 未结 10 1901
-上瘾入骨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:23

    The API is pretty clear about the differences and/or relations between them:


    Collection

    The root interface in the collection hierarchy. A collection represents a group of objects, known as its elements. Some collections allow duplicate elements and others do not. Some are ordered and others unordered.

    http://download.oracle.com/javase/6/docs/api/java/util/Collection.html

    List

    An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.

    http://download.oracle.com/javase/6/docs/api/java/util/List.html

    Set

    A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by its name, this interface models the mathematical set abstraction.

    http://download.oracle.com/javase/6/docs/api/java/util/Set.html

    Map

    An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.

    http://download.oracle.com/javase/6/docs/api/java/util/Map.html


    Is there anything in particular you find confusing about the above? If so, please edit your original question. Thanks.

提交回复
热议问题