The List set is its traversal. The list set

Source: Internet
Author: User

The List set is its traversal. The list set

1. First, List <E> Collection inheritance and Collection <E> is an interface.

① Collection (the Collection framework is JDK1.2)

② List: it is ordered, and elements can be repeated, so that the collection system has an index.

It is often used to implement the ArrayList and ArrayList classes of this interface.

③ Arraylist: the underlying data structure uses an array structure,

Feature: the query speed is fast, but the addition and deletion are slow. Thread not synchronized

Linked list: the bottom layer uses the Linked List data structure.

Features: Fast addition, deletion, and slow query.

Vector :( JDK1.0) the underlying layer is the array data structure, and the thread is synchronized. Replaced by ArrayList. (No more)

2. List traversal methods:

1 public class Demo {2 public static void main (String [] args) {3 ArrayList <String> list = new ArrayList <String> (); 4 list. add ("A"); 5 list. add ("B"); 6 list. add ("C"); 7 8 System. out. println ("........ the first Traversal method: for traversal ...... "); 9 for (Object li: list) {10 System. out. println (li); 11} 12 13 System. out. println ("........ the second Traversal method: ListIterator iterative traversal ...... "); 14 ListIterator <String> it = list. listIterator (); 15 while (it. hasNext () {16 Object obj = it. next (); 17 System. out. println (obj); 18} 19} 20}

:

3. Use LinkList to simulate a stack or queue data structure. Namely: Stack: first-in-first-out; queue: first-in-first-out

Class Duilie {private jsonlist <Object> link; Duilie () {link = new jsonlist <Object> ();} public void myAdd (Object obj) {link. addFirst (obj);} public Object myGet () {return link. removeLast (); // first-in-first-out --- if you want to change to first-out, change removelast () to removeFirst ()} public boolean isNull () {return link. isEmpty () ;}} public class Demo2 {public static void main (String [] args) {Duilie dl = new Duilie (); dl. myAdd ("java01"); d L. myAdd ("java02"); dl. myAdd ("java03"); dl. myAdd ("java04"); while (! Dl. isNull () {System. out. println (dl. myGet ());}}}

:

The above is the first-in-first-out mode. If you want to change it to the first-out mode, you can simply change it based on the code.

 

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.