How to sort elements of a StringBuilder?
763890Mar 5 2010 — edited Mar 8 2010Is there a way of sorting elements of a StringBuilder?
I am wondering if there is a better(more efficient?) way to do the sorting for the StringBuilder.
It seems like the following can get it done:
NOTE: StringBuilder: sb , String: s
Solution A:
1.Sort the s using java.util.Arrays.sort(+s+.getBytes())
2.Append the s in 1. to a sb using append method
Solution B:
1.Append unsorted s to a sb using append method
2.Sort the sb in 1. using java.util.Arrays.sort(+sb+.toString().getBytes)