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