Package com.shushine.framework. Seventh Java standard Class library;
Import java.util.ArrayList;
/**
*
* <p>
* Describe the type of situation {@link represents who has a relationship}
* </p>
*
* @author Wang Chao
* @since 1.0
* @date October 24, 2016 7:46:28
* @see New | modify | Give up
* @see com.shushine.framework. Seventh Java Standard Class library. Arraylistdemo
*/
public class Arraylistdemo {
public static void Main (string[] args) {
Create a ArrayList object
arraylist<string> list = new arraylist<string> ();
SYSTEM.OUT.PRINTLN ("The initial size of the List:" + list.size ());
List.add ("a");
List.add ("B");
List.add ("C");
List.add ("D");
List.add ("E");
List.add ("F");
List.add ("G");
List.add (1, "B");
System.out.println ("Increase the size of the list after the element:" + list.size ());
SYSTEM.OUT.PRINTLN ("List content is:" + list);
Delete Element
List.remove ("a");
List.remove (2);
SYSTEM.OUT.PRINTLN ("Size after deletion:" + list.size ());
System.out.println ("Content:" + list);
Getting an array from ArrayList
arraylist<double> doulist = new arraylist<double> ();
Doulist.add (New Double (10.3));
Doulist.add (New Double (10.4));
Doulist.add (New Double (10.5));
Doulist.add (New Double (10.6));
System.out.println ("doulist:" + doulist);
object[] arr = Doulist.toarray ();
Double sum = 0.0;
for (int i = 0; i < arr.length; i++) {
The object type is first converted to a double type and then converted to a double type
Sum + = ((Double) arr[i]). Doublevalue ();
}
System.out.println ("sum:" + sum);
}
}
ArrayList code example