src/share/classes/java/util/LinkedList.java

Print this page




   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}




   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 double-ended queue}.
  38  *
  39  * <p>The class implements the {@code Deque} interface, providing
  40  * first-in-first-out queue operations for {@code add},
  41  * {@code poll}, along with other stack and deque operations.
  42  *
  43  * <p>All of the operations perform as could be expected for a doubly-linked
  44  * list.  Operations that index into the list will traverse the list from
  45  * the beginning or the end, whichever is closer to the specified index.
  46  *
  47  * <p><strong>Note that this implementation is not synchronized.</strong>
  48  * If multiple threads access a linked list concurrently, and at least
  49  * one of the threads modifies the list structurally, it <i>must</i> be
  50  * synchronized externally.  (A structural modification is any operation
  51  * that adds or deletes one or more elements; merely setting the value of
  52  * an element is not a structural modification.)  This is typically
  53  * accomplished by synchronizing on some object that naturally
  54  * encapsulates the list.
  55  *
  56  * If no such object exists, the list should be "wrapped" using the
  57  * {@link Collections#synchronizedList Collections.synchronizedList}