偶比着<<Java编程思想(第二版)>>写了P361的代码,但是编译的时候出现了很多错误:operator < cannot be applied to int,java.awt.Dismension
cannot resolve symbol method get (int)
cannot resolve symbol method iterator()
cannot resolve symbol method listIterator(int)
...源代码如下:
import java.util.*;
import com.bruceeckel.util.*;public class ListPerformance{
private abstract static class Tester{
String name;
int size;
Tester(String name,int size){
this.name=name;
this.size=size;
}
abstract void test(List a,int reps);
}
private static Tester[] tests={
new Tester("get",300){
void test(List a,int reps){
for (int i = 0; i<reps; i++){
for (int j = 0; j<a.size(); j++)
a.get(j);
}
}
},
new Tester("iteration",300){
void test(List a,int reps){
for (int i = 0; i<reps; i++){
Iterator it=a.iterator();
while(it.hasNext())
it.next();
}
}
},
new Tester("insert",5000){
void test(List a,int reps){
int half=a.size()/2;
String s="test";
ListIterator it=a.listIterator(half);
for (int i = 0; i<size*10; i++)
it.add(s);
}
},
new Tester("remove",5000){
void test(List a,int reps){
ListIterator it =a.listIterator(3);
while(it.hasNext()){
it.next();
it.remove();
}
}
},
};
public static void test(List a,int reps){
System.out.println("Testing"+a.getClass().getName());
for (int i = 0; i<tests.length; i++){
Collections2.fill(a,Collections2.countries.reset(),tests[i].size);
System.out.print(tests[i].name);
long t1=System.currentTimeMillis();
tests[i].test(a,reps);
long t2=System.currentTimeMillis();
System.out.println(": "+(t2-t1));
}
}
public static void testArray(int reps){
System.out.println("Testing array as List");
for (int i = 0; i<2; i++){
String[] sa=new String[tests[i].size];
Arrays2.fill(sa,Collections2.countries.reset());
List a= Arrays.asList(sa);
System.out.print(tests[i].name());
long t1=System.currentTimeMillis();
tests[i].test(a,reps);
long t2=System.currentTimeMillis();
System.out.println(": "+(t2-t1));
}
}
public static void main(String[]args){
int reps=50000;
if(args.length>0)
reps=Integer.parseInt(args[0]);
System.out.println(reps+"repetitions");
testArray(reps);
test(new ArrayList(),reps);
test(new LinkedList(),reps);
test(new Vector(),reps);
}
}
cannot resolve symbol method get (int)
cannot resolve symbol method iterator()
cannot resolve symbol method listIterator(int)
...源代码如下:
import java.util.*;
import com.bruceeckel.util.*;public class ListPerformance{
private abstract static class Tester{
String name;
int size;
Tester(String name,int size){
this.name=name;
this.size=size;
}
abstract void test(List a,int reps);
}
private static Tester[] tests={
new Tester("get",300){
void test(List a,int reps){
for (int i = 0; i<reps; i++){
for (int j = 0; j<a.size(); j++)
a.get(j);
}
}
},
new Tester("iteration",300){
void test(List a,int reps){
for (int i = 0; i<reps; i++){
Iterator it=a.iterator();
while(it.hasNext())
it.next();
}
}
},
new Tester("insert",5000){
void test(List a,int reps){
int half=a.size()/2;
String s="test";
ListIterator it=a.listIterator(half);
for (int i = 0; i<size*10; i++)
it.add(s);
}
},
new Tester("remove",5000){
void test(List a,int reps){
ListIterator it =a.listIterator(3);
while(it.hasNext()){
it.next();
it.remove();
}
}
},
};
public static void test(List a,int reps){
System.out.println("Testing"+a.getClass().getName());
for (int i = 0; i<tests.length; i++){
Collections2.fill(a,Collections2.countries.reset(),tests[i].size);
System.out.print(tests[i].name);
long t1=System.currentTimeMillis();
tests[i].test(a,reps);
long t2=System.currentTimeMillis();
System.out.println(": "+(t2-t1));
}
}
public static void testArray(int reps){
System.out.println("Testing array as List");
for (int i = 0; i<2; i++){
String[] sa=new String[tests[i].size];
Arrays2.fill(sa,Collections2.countries.reset());
List a= Arrays.asList(sa);
System.out.print(tests[i].name());
long t1=System.currentTimeMillis();
tests[i].test(a,reps);
long t2=System.currentTimeMillis();
System.out.println(": "+(t2-t1));
}
}
public static void main(String[]args){
int reps=50000;
if(args.length>0)
reps=Integer.parseInt(args[0]);
System.out.println(reps+"repetitions");
testArray(reps);
test(new ArrayList(),reps);
test(new LinkedList(),reps);
test(new Vector(),reps);
}
}
解决方案 »
- 怎么实现,java读1G以上的txt文件并快速入库?
- html 标记 规范化
- 求教高人一个java bug的问题
- 猴子吃桃问题
- 请java图形高手帮忙,会外语的也可以帮我翻译成英文
- 如何连接sqlserver2000数据库
- 怎么将从数据库表中读出的记录放到ArrayList中
- 有沒有人用過jbuiler裡的queryDataSet,能不能告訴我怎麼用查詢一個寫好的SQL語句?
- 很可气的问题:double a=20011130;System.out.println("实际是:"+a); 显示结果是2.00111E7
- java不能覆盖方法,正在尝试指定更低的访问权限
- 这个问题好怪!请大家看看!谢谢!
- 有关JAVA操作文本的疑惑
public static void testArray(int reps){
System.out.println("Testing array as List");
for (int i = 0; i<2; i++){
String[] sa=new String[tests[i].size];
Arrays2.fill(sa,Collections2.countries.reset());
List a= Arrays.asList(sa);
System.out.print(tests[i].name);//这里改了一下,你对比一下
long t1=System.currentTimeMillis();
tests[i].test(a,reps);
long t2=System.currentTimeMillis();
System.out.println(": "+(t2-t1));
}
}