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
  • 376
  • 5
  • 17
1
List myList = Arrays.asList(myString.split(" "));
Collections.reverse(myList);
String reversed = String.join(" ", myList);
Behrang
  • 44,452
  • 23
  • 114
  • 153