List vs Queue vs Java中的集合集 [英] List vs Queue vs Set of collections in Java

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

问题描述

列表,队列和集合之间有什么区别?

what is the difference among list, queue and set?

推荐答案

简介:

em>是对象的有序列表,其中相同的对象可能出现多次。例如:[1,7,1,3,1,1,1,5]。谈论列表中的第三个元素是有意义的。您可以在列表中的任何位置添加元素,在列表中的任何位置更改元素,或从列表中的任何位置删除元素。

A list is an ordered list of objects, where the same object may well appear more than once. For example: [1, 7, 1, 3, 1, 1, 1, 5]. It makes sense to talk about the "third element" in a list. You can add an element anywhere in the list, change an element anywhere in the list, or remove an element from any position in the list.

队列也是有序的,但你只能在一端触摸元素。所有元素都插入到end并从队列的开头(或头)中删除。你可以知道队列中有多少个元素,但你不能知道什么,比如说,第三元素是。

A queue is also ordered, but you'll only ever touch elements at one end. All elements get inserted at the "end" and removed from the "beginning" (or head) of the queue. You can find out how many elements are in the queue, but you can't find out what, say, the "third" element is. You'll see it when you get there.

未订购,不能包含重复项目。任何给定对象是或不在集合中。 {7,5,3,1}是与{1,7,1,3,1,1,1,5}完全相同的集合。你再也不能要求第三元素或甚至第一元素,因为它们不是任何特定的顺序。您可以添加或删除元素,并且可以确定是否存在某个元素(例如,此集合中是否为7?)

A set is not ordered and cannot contain duplicates. Any given object either is or isn't in the set. {7, 5, 3, 1} is the exact same set as {1, 7, 1, 3, 1, 1, 1, 5}. You again can't ask for the "third" element or even the "first" element, since they are not in any particular order. You can add or remove elements, and you can find out if a certain element exists (e.g., "is 7 in this set?")

这篇关于List vs Queue vs Java中的集合集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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