LinkedList of the Java collection

Source: Internet
Author: User

LinkedList: Located under the Java.util package

1 LinkedList Overview

Features: The underlying data structure is linked list, adding and deleting fast query slow, non-synchronous, thread insecure, efficient, orderly (access order consistent), allow storage of duplicate values, allow the storage of null values, easy to implement stack, queue, two-way queue structure;

Common constructs:

Public LinkedList (): null parameter construct, build an empty list.

Common methods: Similar to ArrayList, only the unique functional methods are listed here.

1) Add Features:

Public AddFirst (e E): Inserts the specified element at the beginning of this list.

Public AddLast (e E): Inserts the specified element at the end of this list.

2) Get Features

Public E Element (): Gets the header (first element) of this list without removing it.

Public E GetFirst (): Returns the first element of this list.

Public E GetLast (): Returns the last element of this list.

3) Delete function

Public E Removefirst (): Removes and returns the first element of this list.

Public E Removelast (): Removes and returns the last element of this list.

4) There are stacks, queue-related functional methods ...

The LinkedList collection belongs to a subclass in the list collection, which uses a similar ArrayList.

2 LinkedList applications

1) Simulation stack structure : The bottom package LinkedList collection, realizes stack stack structure

Package collection.test;

Import java.util.LinkedList;

public class Mystack<t> {
Private linkedlist<t> list;


Public Mystack () {
List = new linkedlist<t> ();
}

Public boolean Add (T obj) {
List.addfirst (obj);
return true;
}

Public Object get () {
return List.removefirst ();
}

public Boolean isEmpty () {
return List.isEmpty ();
}
}

public class Mystacktest {
public static void Main (string[] args) {
mystack<string> stack = new mystack<string> ();
Press Stack
Stack.add ("Hello");
Stack.add ("World");
Stack.add ("Java");
Pop-up stack
while (!stack.isempty ()) {
System.out.println (Stack.get ());
}

}
}

LinkedList of the Java collection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.