I have been trying to figure this out for hours, but I am unable find an answer that works.
For completeness, I have posted the entire code below. If I do not Override
Just call toString() with the List element itself. Like so:
import java.util.List;
import java.util.LinkedList;
public class WordList {
List list = new LinkedList();
public static void main(String []args) {
System.out.println(new WordList());
}
@Override
public String toString() {
String result = "";
list.add("Hello");
list.add("World");
for (int i = 0; i < list.size(); i++) {
result += " " + list.get(i).toString();//call toString on element of the list
}
return result;
}
}
Output: ' Hello World'