How to Get Last Word from String in Java?

Hello friends Today, through this tutorial, I will tell you how to get the last word from the value of any string by java. So let’s go.

Extract Last Word from String Using Java, Fetch Last Word from String by Java Program, Get Last Word from String in Java

It is very easy to get his last word from string via java. You are given below in a very easy way. You can get the last word of string by adding this code to your file.

String test = "Extract Last Word from String Using Java Program";
String lastWord = test.substring(test.lastIndexOf(" ")+1);