I was solving a problem before including it in my code and using List to get strings then work around with them. I got the error: “type List does not take parameters List words = new ArrayList();” after compilation. I searched but the syntax i use is correct, please whats wrong with the code?
import java.util.Scanner;
import java.util.ArrayList;
public class List{
public static void main(String args[]){
List<String> words = new ArrayList<String>();
Scanner input = new Scanner(System.in);
for (int i=0; i < 3; i++)
words.add(input.nextLine());
System.out.println(words);
}
}
This is one of the reasons you should use unique names for your own classes. You are really meaning to use
java.util.List, but since you called your classListas well, the real problem is masked. Rename your class and add the import forjava.util.Listto fix the issue: