0

I want to change place of words in string. it need to be symmetric changing.
Example myString= "This website is so nice"
i want it will be = "nice so is website this"

2 Answers2

1

The following will do what you want:

public static void main(String[] args) {

        StringTokenizer st = new StringTokenizer("This website is so nice");

        String reversed = "";

        while (st.hasMoreTokens()) {
            reversed = st.nextToken() + " " + reversed;
        }

        System.out.println("reversed is :" + reversed);

    }
Storms786
  • 416
  • 1
  • 7
  • 20
1
List myList = Arrays.asList(myString.split(" "));
Collections.reverse(myList);
String reversed = String.join(" ", myList);
Behrang
  • 46,888
  • 25
  • 118
  • 160