public void display()
{
super.display();
String str = super.getChoices();
System.out.println(str);
while(!str.equals(""))
{
int a = str.indexOf(" ");
System.out.println(str.substring(0, a));
String sentence = str.replaceFirst(str, str.substring(a));
System.out.println(sentence);
}
}
I have a String str
containing "Apple Banana Orange". I want to system out print these fruits separately because they are each a choice to a question stored in a single variable. How can I do this? The code above is my failed attempt because the substring doesn't update the str
variable rather creates a new string. I can't use a loop and I can't make it dynamic and thus not use it.