The program is a text engine that takes in a text file and analyzes it.
public Word findFirst(String text) throws SearchableException, ContentNotLoadedException {
for(int i = 0;i<words.size();i++) {
if(text.equals(words.get(i).text)) {
return words.get(i).text;
}
}
}
This is a method that is supposed to return the first instance of a word that matches the input "text." "words" is the array list that loads all the words. I get an error of "can't convert from string to word" in my return statement and while I understand the error, I can't think of an alternative way to go about doing this?
public class Word {
public final String text;
public final int position;
public final int length;
public final int line;
public final int positionInLine;
public Word(String text, int position, int length, int line, int positionInLine) {
this.text = text;
this.position = position;
this.length = length;
this.line = line;
this.positionInLine = positionInLine;
}
This is the Word class in question.
Edit:I am unable to change the method signature or Word class in any way.
public String findFirst...?