Any simpler way to get the last element of a Java array?
java
Solution
Another way to get the last token/word
String lastToken = sentance.replaceAll(".* ", "");
Problem
``` String sentence = "Any simpler way to get the last element of a Java array?"; String lastToken = sentence.split(" ")[sentence.split(" ").length-1]; ``` I'd like to split the sentence and get the last token. I feel my way of doing it is a little too awkward. Basically, I want the second statement to be shorter. Is that possible? Edit: What I'm looking for: 1) no need to declare the array separately 2) no need to split the sentence twice. It would be good if there's a method called `last` with array. I suspect this is impossible but want to make sure.