In this example, we’ll find how to reverse words in a string
Input:
String word = "hello world";
Output:
world hello
1. Java
public class ReverseWordsInString {
public static void main(String[] args) {
String sentence = "Java is Great";
String reversed = "";
String[] split = sentence.split(" ");
for (int i = split.length-1; i >= 0; i--) {
reversed += split[i] + " ";
}
System.out.println(reversed);
}
}
Output:
Great is Java
Complete Java Solutions can be found here: Github Link