Java basic Knowledge Enhancement collection Frame Note 26:linkedlist's unique features

Source: Internet
Author: User

1. Unique features of LinkedList:

(1) Add function
public void AddFirst (Object e)
public void AddLast (Object e)
(2) Get function
Public Object GetFirst ()
Public obejct GetLast ()
(3) Delete function
Public Object Removefirst ()
Public Object Removelast ()

2. code example:

1  Packagecn.itcast_03;2 3 Importjava.util.LinkedList;4 5 /*6 * Unique features of LinkedList:7 * A: Add features8 * public void AddFirst (Object e)9 * public void AddLast (Object e)Ten * B: Get features One * Public Object getfirst () A * Public obejct getlast () - * C: delete function - * Public Object removefirst () the * Public Object removelast () -  */ -  Public classLinkedlistdemo { -      Public Static voidMain (string[] args) { +         //To create a collection object -LinkedList link =NewLinkedList (); +  A         //adding elements atLink.add ("Hello"); -Link.add ("World"); -Link.add ("Java"); -  -         //Public void AddFirst (Object e) -         //link.addfirst ("Java ee"); in         //Public void AddLast (Object e) -         //link.addlast ("Android"); to  +         //Public Object GetFirst () -         //System.out.println ("GetFirst:" + Link.getfirst ()); the         //Public obejct GetLast () *         //System.out.println ("GetLast:" + link.getlast ()); $ Panax Notoginseng         //Public Object Removefirst () -System.out.println ("Removefirst:" +Link.removefirst ()); the         //Public Object removelast () +System.out.println ("Removelast:" +link.removelast ()); A  the         //Output Object Name +System.out.println ("Link:" +link); -     } $}

The results are as follows:

Java basic Knowledge Enhancement collection Frame Note 26:linkedlist's unique features

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.