import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
public class ArrayTest {
private List<Integer> mArrayList;
private Vector<Integer> mVector;
private ArrayTest(){
// mArrayList = Collections.synchronizedList(new ArrayList<String> ());
mArrayList = new ArrayList<Integer>();
mVector = new Vector<Integer>();
}
private synchronized void addList(){
int i = 0;
long oldTimes = System.nanoTime();
while(i <= 99){
mArrayList.add(100);
i++;
}
long nowTimes = System.nanoTime();
System.out.println("add "+(nowTimes-oldTimes));
}
private synchronized void getList(){
long oldTimes = System.nanoTime();
Iterator<Integer> iterator = mArrayList.iterator();
while(iterator.hasNext()){
iterator.next();
}
long nowTimes = System.nanoTime();
System.out.println("get "+(nowTimes-oldTimes));
}
private synchronized void remove(){
int i = 0;
long oldTimes = System.nanoTime();
while(i <= 99){
mArrayList.removeAll(mArrayList);
i++;
}
long nowTimes = System.nanoTime();
System.out.println("remove "+(nowTimes-oldTimes));
}
private synchronized void remove1(){
int i = 0;
long oldTimes = System.nanoTime();
while(i <= 99){
mVector.removeAllElements();
i++;
}
long nowTimes = System.nanoTime();
System.out.println("mVector remove "+(nowTimes-oldTimes));
}
private void addList1(){
int i = 0;
long oldTimes = System.nanoTime();
while(i <= 99){
mVector.add(100);
i++;
}
long nowTimes = System.nanoTime();
System.out.println("mVector add "+(nowTimes-oldTimes));
}
private void getList1(){
long oldTimes = System.nanoTime();
Iterator<Integer> iterator = mVector.iterator();
while(iterator.hasNext()){
iterator.next();
}
long nowTimes = System.nanoTime();
System.out.println("mVector get "+(nowTimes-oldTimes));
}
public static void main(String[] args) {
ArrayTest arrayTest = new ArrayTest();
arrayTest.addList();
arrayTest.getList();
arrayTest.remove();
arrayTest.addList1();
arrayTest.getList1();
arrayTest.remove1();
}
}
add 799077
get 337551
remove 58513
mVector add 48640
mVector get 279402
mVector remove 14995