简体   繁体   中英

java collections vs map in collections framework

According to http://docs.oracle.com/javase/tutorial/collections/interfaces/index.html there are two top level interfaces called collection and map.

Whats the exact reason for separating these two ?

Is it that all key value data structures implement the map interface and all others implement the collections interface ?

Yes, That's correct! Check all the List classes and then check all the Map related classes.

and there is this awesome discussion, ob this question

List vs Map in Java

Visually

This is a collection , by this you know that the books are there and it's in order like 0,1,2,3...

在此输入图像描述

But in a Map , the books are in memory unordered but for the computer's convenience it has a key to find the books, like in a library.

在此输入图像描述

A Map is a structure that has unique keys mapping to values. A Collection is just a grouping of multiple values with no specific key.

You can do the same comparison between a List and a Map to see the differences. This SO question deals with these differences.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM