List vs Map in Java

前端 未结 9 1877
灰色年华
灰色年华 2020-12-02 23:29

I didnt get the sense of Maps in Java. When is it recommended to use a Map instead of a List?

thanks in advance,

nohereman

9条回答
  •  日久生厌
    2020-12-03 00:05

    Maps store data objects with unique keys,therefore provides fast access to stored objects. You may use ConcurrentHashMap in order to achieve concurrency in multi-threaded environments. Whereas lists may store duplicate data and you have to iterate over the data elements in order to access a particular element, therefore provide slow access to stored objects. You may choose any data structure depending upon your requirement.

提交回复
热议问题