java集合查询测试结果

阅读更多
package test.com;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test2 {

	  private static Random random = new Random();
	     public static void main(String[] args){
	         ArrayList arraylist = new ArrayList();
	          LinkedList linkedlist = new LinkedList();
	          HashMap map = new HashMap();
	          HashSet set = new HashSet();
	          for(int i=0;i<50000;i++){
	              String r = randomString();
	              arraylist.add(r);
	              linkedlist.add(r);
	              map.put(r, r);
	              set.add(r);
	          }
	          
	          System.out.println("arraylist size "+arraylist.size());
	          System.out.println("linkedlist size "+linkedlist.size());
	          System.out.println("map size "+map.size());
	          System.out.println("set size "+set.size());
	          
	         
	          System.out.println("------");
	          long begin = System.currentTimeMillis();
	          for(int j=0;j 
 

结果:
arraylist size 50000
linkedlist size 50000
map size 50000
set size 50000
------
arraylist time 52828
linkedlist time 65155
map time 678
set time 666

电脑4G内存

你可能感兴趣的:(java)