Java-9.7 collections list
In this section, we will briefly introduce some methods and features of a listing list.
1. Features
Inserting or deleting an element in the middle will have better performance than the ArrayList, but it may not be certain. Please click (List introduction and performance) and there is a simple test in it.
2. Method demonstration
package com.ray.ch09;import java.util.Arrays;import java.util.LinkedList;public class Test {public static void main(String[] args) {LinkedList
linkedList = new LinkedList
();for (int i = 0; i < 10; i++) {linkedList.add(i);}linkedList.addFirst(12);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 common methods of listing list.
Summary: This chapter briefly introduces the common methods and features of listing.