I'm trying to build a simple dictionary that compares a string to a word on the ArrayList
and then returns a different value from the list. The ArrayList
is laid out with the foreign word and then followed by the English equivalent so the idea is that I type in a word, use scanner to compare it to the array list and then return the index value +1 so if the word I type is 7th on the list, I want it to return the 8th word and print it out.
I've got the basic idea of inputting a string and comparing it, but I don't know how to return the following word from the ArrayList
:
public void translateWords(){
String nameSearch;
nameSearch=input.nextLine();
for (Phrase c:phrases) {
if (c.getName().equals(nameSearch)) {
System.out.println( c.advancedToString());
return;
}
}
System.out.println("not on list");
I've tried playing about with the get method for the ArrayList but I'm unsure on how to use it so any feedback would be very appreciated here.