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.
public class arrayl {
public static void main(String args[] ) throws FileNotFoundException
{
System.out.println("Please enter title of book: ");
Scanner input = new Scanner(System.in);
String search = input.next();
//file with absolute path
Scanner file = new Scanner(new File("c:\\Documents and Settings\\name\\Desktop\\Book.txt"));
//arraylist named as test
ArrayList<String> test = new ArrayList<>();
//creating loop that will read file
while (file.hasNext()){
//adding file to arraylist
test.add(file.next());
}
//Using users input, named search, to find element in the arraylist and print return found or not
System.out.println(test.indexOf(search));
file.close();
}