Java: Simplest way to get last word in a string
String test = "This is a sentence";
String lastWord = test.substring(test.lastIndexOf(" ")+1);
String testString = "This is a sentence";
String[] parts = testString.split(" ");
String lastWord = parts[parts.length - 1];
System.out.println(lastWord); // "sentence"