I am trying to store a file into an ArrayList and then have user input from console search for an element in the Arraylist and return found or not. It keeps giving me -1.
import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.ArrayList; import java.util.Scanner; public class arrayl { public static void main(String args[] ) throws FileNotFoundException { System.out.println("Please enter choice "); Scanner input = new Scanner(System.in); String search = input.next(); Scanner file = new Scanner(new File("c:\\Documents and Settings\\name\\Desktop\\Book.txt")); ArrayList<String> test = new ArrayList<>(); while (file.hasNext()){ test.add(file.next()); } System.out.println(test.indexOf(search)); file.close(); } }