Java List遍历方法 及其效率对比
One:14109
Two:14000
Three:15141
four:14297
package com.zbalpha.test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ListTest {
public static void main(String args[]){
List<Long> lists = new ArrayList<Long>();
for(Long i=0l;i<1000000l;i++){
lists.add(i);
}
Long oneOk = oneMethod(lists);
Long twoOk = twoMethod(lists);
Long threeOk = threeMethod(lists);
Long fourOk = fourMethod(lists);
System.out.println("One:" + oneOk);
System.out.println("Two:" + twoOk);
System.out.println("Three:" + threeOk);
System.out.println("four:" + fourOk);
}
public static Long oneMethod(List<Long> lists){
Long timeStart = System.currentTimeMillis();
for(int i=0;i<lists.size();i++) {
System.out.println(lists.get(i));
}
Long timeStop = System.currentTimeMillis();
return timeStop -timeStart ;
}
&
相关文档:
public static void replaceString(String source,String oldStr,String newStr){
System.out.println(source);
String result = source.replaceAll("(?i)"+oldStr
, newStr); //大小写不敏 ......
线程池类为 java.util.concurrent.ThreadPoolExecutor,常用构造方法为: ThreadPoolExecutor(int corePoolSize, int maximumPoolSize,
long keepAliveTime, TimeUnit unit,
BlockingQueue<Runnable> workQueue,
RejectedExecutionHandler handler) corePoolSize: 线程池维护线程的最少数量 ......
StringTokenizer 这个类其实真正项目里面恐怕很少会用吧?但是这个类真的很实用,因为它可以根据自己的方式按照一定的规则来拆分一个字符串
String s = new String("The Java platform is the ideal platform for network computing");
//默认的构造函数,会 ......
public class Test{
public static void main(String args[]){
System.out.println("This is a test program.");
}
}
将上面的这段程序保存为文件名为Test.java的文件。
然后打开命令提示符窗口,cd到你的Test.java所在目录,然后键入下面的命令
javac Test.java
出错:
类 Test 是公共的,应 ......
1.新建一个servlet程序,文件名为Test.java,文件内容如下:
package test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServle ......