Meet java-9.7 LinkedList from the beginning

Source: Internet
Author: User

In this section we will briefly describe some of the methods and features of a linkedlist.

1. Features

Inserting or deleting elements in the middle can be better than ArrayList, but there is not necessarily a case, click (List Introduction and performance), there is a simple test

2. Method Demo

Package Com.ray.ch09;import Java.util.arrays;import Java.util.linkedlist;public class Test {public static void main ( String[] args) {linkedlist<integer> LinkedList = new linkedlist<integer> (); for (int i = 0; i < i++) {Li Nkedlist.add (i);} Linkedlist.addfirst (n); Linkedlist.addlast (15); System.out.println (Arrays.tostring (Linkedlist.toarray ())); System.out.println (Linkedlist.removelast ()); System.out.println (Linkedlist.remove ()); System.out.println (Arrays.tostring (Linkedlist.toarray ())); System.out.println (Linkedlist.poll ()); System.out.println (Linkedlist.peek ()); System.out.println (Arrays.tostring (Linkedlist.toarray ()));}}


Output:

[12, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 15]
15
12
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
0
1
[1, 2, 3, 4, 5, 6, 7, 8, 9]

The above code mainly demonstrates some of the methods commonly used by LinkedList.

Summary: This chapter briefly introduces the common methods and characteristics of LinkedList.

This chapter is here, thank you.

-----------------------------------

Directory

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Meet java-9.7 LinkedList from the beginning

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.