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