Package cn.itcast_03;
Import java.util.ArrayList;
Import java.util.List;
/*
* Unique features of the list collection:
* A: Add features
* void add(int index,objectElement): adding elements at the specified location
* B: Get features
* Object get(int index): gets The element at the specified position
* C: List iterator
* listiterator listiterator():List Collection-specific iterator
* D: delete function
* Object Remove (int index): Deletes the element according to the index, returns the element that was deleted , ( To delete you and return you.)
* E: Modify function
* Object set(int index,objectElement): modifies elements according to index, returns modified elements
*/
public class Listdemo {
public static void Main (string[] args) {
To Create a Collection object
List List = new ArrayList ();
adding elements
List.add ("Hello");
List.add ("World");
List.add ("Java");
void Add (int index,object Element): add element at specified position
List.add (1, "Android");//No problem
indexoutofboundsexception( index out of bounds)
List.add (One, "Java ee");//problem
List.add (3, "Java ee"); No problem
List.add (4, "Java ee"); Have a problem
Object get (int index): Gets the element at the specified position
System.out.println ("Get:" + list.get (1));
Indexoutofboundsexception (index out of bounds)
System.out.println ("Get:" + list.get (11));
Object Remove (int index): Deletes elements based on index, returns deleted elements
System.out.println ("Remove:" + list.remove (1));
Indexoutofboundsexception (index out of bounds)
System.out.println ("Remove:" + list.remove (11));
Object set (int index,object element): Modifies the element according to the index, returning the modified element
System.out.println ("set:" + list.set (1, "Java ee")); The index is starting at 0 , which means that index 0 represents the Helloin the list collection, and the result returned by this method is the world (the modified element) the element at this time is Hello,javaee,java
System.out.println ("list:" + list);
}
}
This article is from the "GD" blog, please be sure to keep this source http://wangdenghui.blog.51cto.com/9930072/1768739
Collection Framework (Unique features overview and testing of the list collection)