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"
Asked
Active
Viewed 85 times
0
-
1What have you tried so far? – Beri Oct 25 '18 at 12:04
2 Answers
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