9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.util; 27 28 /** 29 * Linked list implementation of the {@code List} interface. Implements all 30 * optional list operations, and permits all elements (including 31 * {@code null}). In addition to implementing the {@code List} interface, 32 * the {@code LinkedList} class provides uniformly named methods to 33 * {@code get}, {@code remove} and {@code insert} an element at the 34 * beginning and end of the list. These operations allow linked lists to be 35 * used as a stack, {@linkplain Queue queue}, or {@linkplain Deque 36 * double-ended queue}. 37 * 38 * <p>The class implements the {@code Deque} interface, providing 39 * first-in-first-out queue operations for {@code add}, 40 * {@code poll}, along with other stack and deque operations. 41 * 42 * <p>All of the operations perform as could be expected for a doubly-linked 43 * list. Operations that index into the list will traverse the list from 44 * the beginning or the end, whichever is closer to the specified index. 45 * 46 * <p><strong>Note that this implementation is not synchronized.</strong> 47 * If multiple threads access a linked list concurrently, and at least 48 * one of the threads modifies the list structurally, it <i>must</i> be 49 * synchronized externally. (A structural modification is any operation 50 * that adds or deletes one or more elements; merely setting the value of 51 * an element is not a structural modification.) This is typically 52 * accomplished by synchronizing on some object that naturally 53 * encapsulates the list. 54 * 55 * If no such object exists, the list should be "wrapped" using the 56 * {@link Collections#synchronizedList Collections.synchronizedList} 57 * method. This is best done at creation time, to prevent accidental 58 * unsynchronized access to the list:<pre> 59 * List list = Collections.synchronizedList(new LinkedList(...));</pre> 60 * | 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.util; 27 28 /** 29 * Linked list implementation of the {@code List} interface. 30 * Implements all optional list operations, and permits all elements 31 * (including {@code null}). In addition to implementing the {@code 32 * List} interface, the {@code LinkedList} class provides uniformly 33 * named methods to {@code get}, {@code remove} and {@code add} an 34 * element at the beginning (<i>operation</i>{@code First}) and end 35 * (<i>operation</i>{@code Last}) of the list. These operations allow 36 * linked lists to be used as a stack, {@linkplain Queue queue}, or 37 * {@linkplain Deque deque} (double-ended queue); by implementing the 38 * {@link Deque} interface, support is included for first-in-first-out 39 * operations for {@code add} and {@code poll}. 40 * 41 * <p>All of the operations perform as could be expected for a doubly-linked 42 * list. Operations that index into the list will traverse the list from 43 * the beginning or the end, whichever is closer to the specified index. 44 * 45 * <p><strong>Note that this implementation is not synchronized.</strong> 46 * If multiple threads access a linked list concurrently, and at least 47 * one of the threads modifies the list structurally, it <i>must</i> be 48 * synchronized externally. (A structural modification is any operation 49 * that adds or deletes one or more elements; merely setting the value of 50 * an element is not a structural modification.) This is typically 51 * accomplished by synchronizing on some object that naturally 52 * encapsulates the list. 53 * 54 * If no such object exists, the list should be "wrapped" using the 55 * {@link Collections#synchronizedList Collections.synchronizedList} 56 * method. This is best done at creation time, to prevent accidental 57 * unsynchronized access to the list:<pre> 58 * List list = Collections.synchronizedList(new LinkedList(...));</pre> 59 * |