What is the easiest way to get every word in a line different from the last word in a line? So far, I have used the following code to get the last word:
String listOfWords = "This is a sentence"; String[] b = listOfWords.split("\\s+"); String lastWord = b[b.length - 1];
And then leaving the rest of the line using the remove method to remove the last word from the line.
I donβt want to use the remove method, is there a way, similar to the above code set, to get a variable of a string of words without the last word and last space?
source share