List vs Queue vs Set of collections in Java(Java中的列表vs队列vs集合)
问题描述
列表、队列和集合有什么区别?
what is the difference among list, queue and set?
推荐答案
简而言之:
list 是对象的有序列表,其中同一个对象很可能出现多次.例如:[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.
queue 也是有序的,但你只会在一端接触元素.所有元素都被插入到队列的结束"并从队列的开始"(或头部)中删除.您可以找出队列中有多少元素,但无法找出第三个"元素是什么.当你到达那里时,你会看到它.
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.
set 没有顺序,不能包含重复项.任何给定的对象要么在集合中,要么不在集合中.{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?")
这篇关于Java中的列表vs队列vs集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java中的列表vs队列vs集合


- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01