初学java,做一个练习,总是说List<Integer> list; ArrayList<Integer> aList;找不到符号 求高人解答 20
importjava.util.ArrayList;importstaticorg.junit.Assert.*;importorg.junit.After;import...
import java.util.ArrayList;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* The test class RunTimeComparison.
*
* @author (your name)
* @version (a version number or a date)
*/
public class RunTimeComparison {
public static void main(String args[]) {
int N = 10000000;
long startTime;
long stopTime;
List<Integer> list;
ArrayList<Integer> aList;
/* Create an array with N Integer objects */
Integer array[] = new Integer[N];
for (int i=0; i<N; i++) {
array[i] = new Integer(i);
}
/* Convert array into a List object (list) using the Arrays class */
List<Integer> list1= new List<Integer>();
for (int i=0; i<N; i++) {
list1.get[i] = array[i];
}
/* Convert the List object into an ArrayList object (aList) */
for (int i=0; i<N; i++) {
aList[i] = list[i];
}
/* Run-time using Iterator */
startTime=Date.getTime();
Iterator it = notes.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
stopTime=Date.getTime();
System.out.println("Running Time using Iterator = "+(stopTime-startTime));
/* Run-time using array indexing */
startTime=Date.getTime();
int index = 0;
while(index < notes.size())
{
System.out.println(notes.get(index));
index++;
}
stopTime=Date.getTime();
System.out.println("Running Time using Indexing = "+(stopTime-startTime));
}
} 展开
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* The test class RunTimeComparison.
*
* @author (your name)
* @version (a version number or a date)
*/
public class RunTimeComparison {
public static void main(String args[]) {
int N = 10000000;
long startTime;
long stopTime;
List<Integer> list;
ArrayList<Integer> aList;
/* Create an array with N Integer objects */
Integer array[] = new Integer[N];
for (int i=0; i<N; i++) {
array[i] = new Integer(i);
}
/* Convert array into a List object (list) using the Arrays class */
List<Integer> list1= new List<Integer>();
for (int i=0; i<N; i++) {
list1.get[i] = array[i];
}
/* Convert the List object into an ArrayList object (aList) */
for (int i=0; i<N; i++) {
aList[i] = list[i];
}
/* Run-time using Iterator */
startTime=Date.getTime();
Iterator it = notes.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
stopTime=Date.getTime();
System.out.println("Running Time using Iterator = "+(stopTime-startTime));
/* Run-time using array indexing */
startTime=Date.getTime();
int index = 0;
while(index < notes.size())
{
System.out.println(notes.get(index));
index++;
}
stopTime=Date.getTime();
System.out.println("Running Time using Indexing = "+(stopTime-startTime));
}
} 展开
4个回答
展开全部
看看List<Integer> list; ArrayList<Integer> aList创建那快有没有出问题
还有
List<Integer> list1= new List<Integer>();改为
List<Integer> list1= new ArrayList<Integer>();
还有
List<Integer> list1= new List<Integer>();改为
List<Integer> list1= new ArrayList<Integer>();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你那个aList 没有初始化
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
new ArrayList();
需要
import java.util.*;
具体哪个类我也不知道
需要
import java.util.*;
具体哪个类我也不知道
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询