The basic method of LinkedList collection in Java programming language demo

Source: Internet
Author: User




The basic method of LinkedList collection in Java programming language demo



Import Java.util.iterator;import Java.util.linkedlist;public class Linkedlistdemos {public static void main (string[] args) {//Create a new container linkedlist  link = new LinkedList (); Link.addfirst ("ABC1"); Link.addfirst ("ABC2"); Link.addfirst (" ABC3 "); Link.addfirst (" ABC4 "); Link.addfirst (" Abc5 "); Iterator it = Link.iterator (); while (It.hasnext ()) { System.out.println (It.next ());} System.out.println ("Gets the first element in the collection:" +link.getfirst ()); System.out.println ("Gets the last element in the collection:" +link.getlast ()); System.out.println ("Gets the first element in the collection and deletes the element:" +link.removefirst ()); System.out.println ("Gets the last element in the collection and deletes the element:" +link.removelast ());}}



To run the program:












The basic method of LinkedList collection in Java programming language demo

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.