简体   繁体   English

java集合与集合框架中的映射

[英]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. 根据http://docs.oracle.com/javase/tutorial/collections/interfaces/index.html ,有两个顶级接口,称为集合和映射。

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 ? 是否所有键值数据结构都实现了map接口,而所有其他键值数据结构都实现了collection接口?

Yes, That's correct! 对,那是正确的! Check all the List classes and then check all the Map related classes. 检查所有List类,然后检查所有Map相关类。

and there is this awesome discussion, ob this question 在这个问题上,有这个令人敬畏的讨论

List vs Map in Java 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... 这是一个集合 ,你知道这些书是在那里,它的顺序就像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. Map是具有映射到值的唯一键的结构。 A Collection is just a grouping of multiple values with no specific key. Collection只是一组没有特定键的多个值的组合。

You can do the same comparison between a List and a Map to see the differences. 您可以在ListMap之间进行相同的比较以查看差异。 This SO question deals with these differences. 这个SO问题涉及这些差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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