I am trying to tell whether that string was found in the list or not. For instance, if I put Max in my list and search for Max, it should say "Max was found" If not, then it should say "Max was not found"
I do not know how to approach to getting the answer from here.
import java.util.ArrayList;
import java.util.Scanner;
public class OnTheList {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<String> list = new ArrayList<>();
while (true) {
String input = scanner.nextLine();
if (input.equals("")) {
break;
}
list.add(input);
}
System.out.print("Search for? ");
System.out.print(scanner.nextLine());
if (list.contains(list)) ----> I think this is the part where I am not getting it
System.out.println(" was found!");
else
System.out.println(" was not found");
}
}
list.contains(list)is checking whether the list contains itself. Hint 2: your finalscanner.nextLine()call is just used to print something, but you're not "remembering" that in a variable anywhere. How are you meant to know what you're checking for?