Java-9.7 collections list

Source: Internet
Author: User

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.

 

 

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.