Reverse words in a given string.

Reverse words in a given string.

Write a Java program that takes a string S as input and reverses the order of the words while keeping the individual words unchanged. The input string will be a series of words separated by dots (.).

Question - GeeksForGeeks

import java.awt.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

import static java.lang.System.in;

public class demo {
    public static void main(String[] args) {

        String S = "i.like.this.program.very.much";

        String[] arr = S.split("\\.");
        int arrLen = arr.length;
        int x = arrLen-1;

        List<String> result = new ArrayList<>();
        for (int i=x; i>=0; i--){
            if(x>=i && i!=0) {
                result.add(arr[i] + ".");
            }
            else{
                result.add(arr[i]);
            }
        }
        StringBuilder sb = new StringBuilder();
        for (String str : result) {
            sb.append(str);
        }
        String reverseString = sb.toString();
        System.out.println(reverseString);



    }// write all the code above this line
}