I'm a Java beginner currently using Java version 8. While I was coding, I had the following problem, but I really cannot find what the problem is. I tried to create an ArrayList by declaring...
ArrayList al=new ArrayList(100000);
...which has an initial capacity of 100000. But the program returns an error saying...
The constructor ArrayList(int) is undefined.
To make sure, I even searched for the API Documentation of class java.util.ArrayList, which, of course, said...
ArrayList(int initialCapacity):
Constructs an empty list with the specified initial capacity.
...in its Constructor summary.
Also, the second problem is:
After I declared ArrayList, I tried to use it as an argument for the add method, but it says...
The method add(List) in the type ArrayList3 is not applicable for the arguments (ArrayList).
My full code is here:
import java.util.*;
public class ArrayList3 {
public static void main(String[] args) {
ArrayList al=new ArrayList(100000);
LinkedList ll=new LinkedList();
System.out.println("ArrayList: "+add(al));
System.out.println("LinkedList: "+add(ll));
}
public static long add(List list) {
long start = System.currentTimeMillis();
for(int i=0;i<10000;i++)
list.add(i+" ");
long end = System.currentTimeMillis();
return start - end;
}
}
What would be the problem, and what could have I missed? Thank you very much in advance!
ArrayList3class. I'm guessing you have (or had as some point) a customArrayListclass too.ArrayListin the same source file or in the same package asArrayList3(not surprising as the class you show here is calledArrayList3)