I have seen other threads on this, but I still don't understand the best approach. Issue is as started: One can't compare user input that is a String to an arrayList item (object). My List will be over 40 items.
So when I try to compare classesList.get(0)
to the user input mage
. It won't work.
List<String> classesList = new ArrayList<String>();
classesList.add("mage");
classesList.add("warrior");
classesList.add("thief");
Scanner input = new Scanner(System.in);
String input = input.next();
for (int counter = 0; counter < classesList.size(); counter++) {
if (input == classesList.get(counter)) {
//won't run body since can't compare
}
}
I found some who converted the arrayList to be a String. But I am unsure how I could then easily search through my list. I'd much rather leave it as a List instead. Is the best method to this approach?
String[] classesArray = classesList.toArray(new String[classesList.size()]);