public static void main(String args[]) {
List<String> strList = new ArrayList<String>();
strList.add("username");
strList.add("created");
strList.add("disabled");
strList.add("locked");
strList.add("expired");
long begin = System.currentTimeMillis();
for(int index = 0; index < 100000; index++) {
strList.add("duyang");
strList.remove("duyang");
}
long end = System.currentTimeMillis();
System.out.println("List cost : " + (end-begin));
String[] strArray = new String[] {"username", "created", "disabled", "locked", "expired" };
begin = System.currentTimeMillis();
for(int index = 0; index < 100000; index++) {
List<String> tempList = new ArrayList<String>(Arrays.asList(strArray));
tempList.add("duyang");
tempList.remove("duyang");
strArray = tempList.toArray(new String[]{});
}
end = System.currentTimeMillis();
System.out.println("array cost(include one times Arrays.aslist) : " + (end-begin));
}
结果为:
[table]
|List cost : 10|
|array cost(include one times Arrays.aslist) : 115|
[/table]