日期:2014-05-20 浏览次数:20722 次
public static void main(String[] args)
{
Main ins = new Main();
int size = 10000000;
ins.method1(size);
ins.method2(size);
ins.method3(size);
}
public void method1(int size)
{
long start = System.currentTimeMillis();
ArrayList<String> al = new ArrayList<String>();
String str = null;
try
{
for (int i = 0; i < size; i++)
{
str = "str" + i;
al.add(str);
}
}
catch (Exception e)
{
}
System.out.println("method1 total: " + (System.currentTimeMillis() - start));
}
public void method2(int size)
{
long start = System.currentTimeMillis();
ArrayList<String> al = new ArrayList<String>();
String str = null;
for (int i = 0; i < size; i++)
{
try
{
str = "str" + i;