Lists,ArrayLists,Maps,Hashmaps,Collections等有什么区别..? [英] What is the difference between Lists, ArrayLists, Maps, Hashmaps, Collections etc..?

查看:149
本文介绍了Lists,ArrayLists,Maps,Hashmaps,Collections等有什么区别..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用HashMaps,因为我在Java中再次开始编程而没有真正了解这些Collections的事情。

I've been using HashMaps since I started programming again in Java without really understanding these Collections thing.

老实说我不确定是否一直使用HashMaps对我或生产代码最好。到目前为止,只要我能够以我在PHP中调用它的方式获取我需要的数据对我来说无关紧要(是的,我承认你现在正在考虑的任何负面的事情) $ this_is_array [ 'this_is_a_string_index'] 提供这么多的方便回顾一个变量数组。

Honestly I am not really sure if using HashMaps all the way would be best for me or for production code. Up until now it didn't matter to me as long as I was able to get the data I need the way I called them in PHP (yes, I admit whatever negative thing you are thinking right now) where $this_is_array['this_is_a_string_index'] provides so much convenience to recall an array of variables.

所以,现在,我已用java工作超过3个月,遇到了我上面指定的接口,并想知道,为什么有这么多东西(更不用说,矢量,抽象列表{哦,列表继续...}}?

So now, I have been working with java for more than 3 months and came across the Interfaces I specified above and wondered, why are there so many of these things (not to mention, vectors, abstractList {oh well the list goes on...})?

我的意思是它们彼此之间有什么不同?

I mean how are they different from each other?

更重要的是,在我的案例中使用的最佳界面是什么?

And more importantly, what is the best Interface to use in my case?

推荐答案

API很清楚它们之间的差异和/或关系:

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

集合层次结构中的根接口。集合表示一组对象,称为其元素。有些集合允许重复元素而其他集合则不允许。有些是订购的,有些是无序的。

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

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

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

不包含重复元素的集合。更正式地说,集合不包含元素对e1和e2,使得e1.equals(e2)和至多一个null元素。正如其名称所暗示的,此接口模拟数学集抽象。

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

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

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.

这篇关于Lists,ArrayLists,Maps,Hashmaps,Collections等有什么区别..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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