Set和List有什么区别?

Set和List有什么区别?

问题描述:

设置< E> 列表< E> 接口之间的根本区别是什么?

What is the fundamental difference between the Set<E> and List<E> interfaces?

列表是一个有序的元素序列,而 Set 是一个不同的元素列表(谢谢, Quinn Taylor )。

List is an ordered sequence of elements whereas Set is a distinct list of elements which is unordered (thank you, Quinn Taylor).

列表< E>:


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

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.

设置< E>:


一个集合不包含
重复元素。更正式地说,
集合不包含元素对e1
和e2,使得e1.equals(e2)和
中的大多数空元素。正如
所暗示的那样,这个界面模拟
数学集抽象。

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.