String filename = "example.txt"; String extension = StringUtils.substringAfterLast(filename, "."); System.out.println(extension); // output: "txt"
String sentence = "The quick brown fox jumps over the lazy dog"; String lastWord = StringUtils.substringAfterLast(sentence, " "); System.out.println(lastWord); // output: "dog"Here, we use the space character as the delimiter to get the last word in the sentence. These examples demonstrate the usefulness of the StringUtils class in performing common string manipulation tasks in Java. The StringUtils class is part of the Apache Commons Lang3 library.