I have to create a java program using either a regualr array or arraylist so I chose arralist and I named it horses but now have to create another method with in the programming inorder for a user to input/search for "trigger" and if it is found it shows the position if its not there it returns a -1. any tips would be helpful I just need help in getting it so the user as to input what they want to search for.


  /* so I have a list of horses now I need to create another method inorder for the user to input "trigger" and return the index
  of trigger which would be 0 or if they put in "harry" it will return a -1 for some reaosn my brain is not functioning I can return
  it by having it in pre disclosed in program but cant remember how to have the user input. help me if can"

        /*public int findhorsespace(String name)
        this is what it should be put into this method inorder to return it */

Just loop the array or the ArrayList until you find the element that is equals with the input. If you are using Strings use the equals method. If you find it return the index of the for loop. If the loop finishes without finding anything return -1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.