I am trying to ask if a list contains a certain string.
public void searchList(Scanner scan, Object list){
System.out.println("Search for element:\t");
String p = scan.nextLine();
if (list.contains(p))
System.out.println(p + " is in the list");
else
System.out.println(p + " is not in the list.");
}
I am getting:
Prog7Methods.java:23: cannot find symbol
symbol : method contains(java.lang.String)
location: class java.lang.Object
if (list.contains(p))
I do not understand! I have imported java.io.* and java.util.* how does it not recognize this?
You need to declare the list as a List. Instead of
use
or even better: