Hi, new question regarding deletion of the first word in a string. i have a string, i'd like to to remove the first word in it, print the new and shorter string, remove the first word in the shorter string and keep going like this until there aren't any more words to remove, i've used this code:
import java.io.*;
class Testar {
public static void main(String[] args) {
String partDesc = "Hi my name is SandraPandra";
while (partDesc !="SandraPandra") {
String newString = partDesc.replaceFirst("^(\\w+)\\s+","");
System.out.println (partDesc);
partDesc = newString;}
}
}
i wrote SandraPandra since this is the last word and that's where i'd like it to stop. the thing is, it doesn't , it keeps writing SandraPandra until i interrupt it. anyone understands why this is?