November 2006
Intermediate to advanced
224 pages
3h 29m
English
String letters = "ABCDEF"; StringBuffer lettersBuff = new StringBuffer(letters); String lettersRev = lettersBuff.reverse().toString(); |
The StringBuffer class contains a reverse() method that returns a StringBuffer that contains the characters from the original StringBuffer reversed. A StringBuffer is easily converted into a String using the toString() method of the StringBuffer. So by temporarily making use of a StringBuffer, you are able to produce a second string with the characters of an original string in reverse order.
If you are using JDK 1.5, you can use the StringBuilder class instead of the StringBuffer class. The StringBuilder class has an API compatible with the StringBuffer class. The StringBuilder ...
Read now
Unlock full access