列表与Java中的映射 [英] List vs Map in Java

查看:105
本文介绍了列表与Java中的映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有在Java中找到Maps的感觉。何时建议使用地图而不是列表?



提前感谢,



nohereman

p>

解决方案


Java map:将键映射到值的对象。地图不能包含重复的键;每个键可以映射到最多一个值。



Java列表:有序集合(也称为序列)。该界面的用户可以精确控制列表中每个元素的插入位置。用户可以通过整数索引(列表中的位置)访问元素,并搜索列表中的元素。


区别在于他们是不同的。地图是键/值的映射,是项目列表的列表。


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

解决方案

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

Java 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.

The difference is that they are different. Map is a mapping of key/values, a list of a list of items.

这篇关于列表与Java中的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆