import java.util.*;

class A
{
 public static void main(String args[]){

  String[] a = new String[10000];
  for(int i=0;i<10000;i++){
  a[i]=""+i;
  }
        a[0]="nimabi";
  a[9999]="nimabi";
  Set b = new HashSet();
  long t1 = System.currentTimeMillis();
        for(int i=0;i<10000;i++){
       
    if(!b.add(a[i])){
    System.out.println("找到了"+(i+1));
    };

  }
 long t2 = System.currentTimeMillis();
 System.out.println("set的时间是"+(t2-t1));

 //for循环
   long t3 = System.currentTimeMillis();
   for(int i=0;i<10000;i++){
for(int j=0;j<i;j++){
if(a[j].equals(a[i])){
  System.out.println("找到了"+(i+1));
}
}
 }
 long t4 = System.currentTimeMillis();
 System.out.println("set的时间是"+(t4-t3));


//array
ArrayList c = new ArrayList();
 long t5 = System.currentTimeMillis();
 for(int i=0;i<10000;i++){
 if(c.contains(a[i])){
  System.out.println("找到了"+(i+1));
 }
 c.add(a[i]);
 
 }
long t6 = System.currentTimeMillis();
 System.out.println("set的时间是"+(t6-t5));

//treeset
     TreeSet  d= new TreeSet();
  long t7 = System.currentTimeMillis();
        for(int i=0;i<10000;i++){
    if(!d.add(a[i])){
    System.out.println("找到了"+(i+1));
    }

  }
 long t8 = System.currentTimeMillis();
 System.out.println("set的时间是"+(t8-t7));

}

}

相关文章:

  • 2022-02-06
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-08
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2021-11-12
相关资源
相似解决方案