I'm learning the java collection framework and unable to figure out what is actually causing the error and here I'm using eclipse 4.18.0 and java version 15. There is some problem in the setup because the code is working fine in vs code.
package lists;
import java.util.ArrayList;
import java.util.List;
public class ArrayListCreate {
public static void main(String[] args) {
List<String> fruits=new ArrayList<>();
fruits.add("Apple");
System.out.println(fruits);
}
}
Error : Exception in thread "main" java.lang.Error: Unresolved compilation problems: List cannot be resolved to a type ArrayList cannot be resolved to a type
at lists.ArrayListCreate.main(ArrayListCreate.java:6)
List<String> fruits=new ArrayList<>();You need to specify the type of list to be created or use diamond operator - Rohan Kumarlists.ArrayListCreate.main(ArrayListCreate.java:21). But your file does not seem to be having even 10 lines. Are you sure you've shared complete file with us? - Rohan Kumar