源码分析——What is LinkedList

Doubly-linked list implementation of the {@code List} and {@code Deque}interfaces.  Implements all optional list operations, and permits all elements (including {@code null}).

双向链表实现了List接口和Deque接口。实现所有list的操作,并允许所有元素(包括{@code null})。


 <p>All of the operations perform as could be expected for a doubly-linked list.  Operations that index into the list will traverse the list from the beginning or the end, whichever is closer to the specified index.

 对于双向链表,所有操作都可以预期。索引到列表中的操作将从开头或结尾遍历列表,以较接近指定索引为准。


 <p><strong>Note that this implementation is not synchronized.</strong> If multiple threads access a linked list concurrently, and at least one of the threads modifies the list structurally, it <i>must</i> be synchronized externally.  (A structural modification is any operation that adds or deletes one or more elements; merely setting the value of an element is not a structural modification.)  This is typically accomplished by synchronizing on some object that naturally encapsulates the list.

请注意,此实现未同步。如果多个线程同时访问链接列表,并且至少有一个线程在结构上修改了列表,则必须同步外部。 (结构修改是添加或删除一个或多个元素的任何操作;仅设置元素的值不是结构修改。)这通常通过同步自然封装列表的某个对象来完成。


If no such object exists, the list should be "wrapped" using the {@link Collections#synchronizedList ollections.synchronizedList}
 method.  This is best done at creation time, to prevent accidental unsynchronized access to the list:<pre>   List list = Collections.synchronizedList(new LinkedList(...));</pre>


 如果不存在此类对象,则应使用{@link CollectionssynchronizedList ollections.synchronizedList}“包装”该列表。
方法。这最好在创建时完成,以防止意外地不同步访问列表:<pre> List list = Collections.synchronizedList(new LinkedList(...)); </ pre>


 <p>The iterators returned by this class's {@code iterator} and {@code listIterator} methods are <i>fail-fast</i>: if the list is
 structurally modified at any time after the iterator is created, in any way except through the Iterator's own {@code remove} or
 {@code add} methods, the iterator will throw a {@link ConcurrentModificationException}.  Thus, in the face of concurrent
 modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined
 time in the future.

此类的{@code iterator}和{@code listIterator}方法返回的迭代器是 fail-fast :如果列表是在创建迭代器之后的任何时候进行结构修改,除了通过Iterator自己的{@code remove}或者{@code add}方法,迭代器将抛出{@link ConcurrentModificationException}。因此,面对并发修改,迭代器快速而干净地失败,而不是冒着未确定的任意,非确定性行为的风险in the future。


  <p>Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification.  Fail-fast iterators throw {@code ConcurrentModificationException} on a best-effort basis. Therefore, it would be wrong to write a program that depended on this
 exception for its correctness:   <i>the fail-fast behavior of iterators should be used only to detect bugs.</i>

请注意,迭代器的 fail-fast行为无法得到保证,因为一般来说,在存在非同步并发修改的情况下,不可能做出任何硬性保证。失败快速的迭代器会尽最大努力抛出{@code ConcurrentModificationException}。因此,编写一个依赖于此异常的程序来保证正确性是错误的:迭代器的fail-fast 行为应仅用于检测错误。
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值