ArrayList of three kinds of lists

Source: Internet
Author: User

Arraylist

The underlying implementation is an array, query blocks, additions and deletions are slow. Thread is unsafe, but high efficiency

Vector

The underlying implementation is an array, query blocks, additions and deletions are slow. Thread-safe, low-efficiency.

LinkedList

The underlying implementation is linked list, query slow, adding and deleting blocks, thread insecure, high efficiency


Arraylist

Case one: simple storage and traversal, storing strings

ArrayList array=new ArrayList () array.add ("Hello"); Array.add ("Csz"); Array.add ("LC"); Iterator it=array.iterator (); while (It.hasnext ()) {string s= (String) it.next (); System.out.println (s);}

Case two: Storing custom objects Student

ArrayList array=new ArrayList (); Student s1=new Student (2, "carp"); Student s2=new Student (21, "Chen Shuze"); Student s3=new Student (23, "Zhang Tingting"); Student s4=new Student (26, "John Doe"); Array.add (S1); Array.add (S2); Array.add (S3); Array.add (S4); Iterator it= Array.iterator (); while (It.hasnext ()) {Student s= (Student) it.next (); System.out.println (s);} for (int i=0;i<array.size (); i++) {Student s= (Student) array.get (i); System.out.println (s);}


ArrayList of three kinds of lists

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.