Jeel Shah
Jeel Shah

Reputation: 3324

How can i rearrange the contents within a string? Java

I was wondering how I can rearrange the contents within a string. For example, if it was String s = "Stack,over,flow"; How can I change the position of flow with stack or stack with over?

Upvotes: 2

Views: 1413

Answers (1)

James.Xu
James.Xu

Reputation: 8295

there is not built-in support, the most obvious solution i think is:

String s = "Stack,over,flow";
String[] arr = s.split(",");
// now you have all the parts in arr, you can reconstrut your new string here.

Upvotes: 2

Related Questions