Packagelianxi1;Importjava.util.ArrayList;Importjava.util.Date;Importjava.util.List;Importorg.junit.Test; Public classtestlist {@Test Public voidtest1 () {List List=NewArrayList (); List.add (55);//first elementList.add (35.432); List.add ("RR"); List.add (NewStudent ("3001", "WU") ; The//student class must override the Equals method System.out.println (list); List.add (1, "Tian");//The collection is calculated starting at 0, actually inserting the element in the second position, moving the second and subsequent elements to the rightList.remove (2); SYSTEM.OUT.PRINTLN (list); List.set (3,NewDate ()); SYSTEM.OUT.PRINTLN (list); List List2= List.sublist (0, 1); System.out.println (LIST2); }}
Results:
[35.432, RR, Student [id=3001, Name=wu]]
[Tian, RR, Student [id=3001, Name=wu]]
[Tian, RR, Fri Dec 22:16:44 CST 2014]
[55]
LinkedList class: Implementing linked Lists for frequent insert and delete operations
Vector class: The old implementation class, thread is safe. Not now, basically.
List Common methods