How do I reverse a string?
Category: java.lang, viewed: 27660 time(s).
Below is an example code that reverse a string. Here we use a StringBuffer.reverse() method to reverse a string. In a 1.5 version a new class called StringBuilder also has a reverse() method that do just the same, one of the difference is StringBuffer class is synchronized while StringBuilder class does not.
Beside using this simple method you can try to reverse a string by converting it to character array and then reverse the array order. So here is the string reverse in the StringBuffer way.
And below is the result.
Normal : Morning of The World - The Last Paradise on Earth Reverse: htraE no esidaraP tsaL ehT - dlroW ehT fo gninroM
Can't find what you are looking for? Join our FORUMS and ask some questions!
Download Hundreds of Complimentary Industry Resources
Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more;
all available at no cost to you. With more than 600 complimentary offers, you'll find
plenty of titles to suit your professional interests and needs.
Click Here and Sign up today!
