Method 1: Use the reverse () method of the stringbuilder class
Public class test {
Public static void main (string [] ARGs ){
String STR = "ABC ";
String restr = new stringbuilder (STR). Reverse (). tostring (); // reverse using the reverse () method of the stringbuilder class
System. Out. println (restr );
}
}
Method 2: Use the stack to implement and take advantage of its advanced features.
Import java. util. Stack;
Import java. util. vector;
Public class test {
Public static void main (string [] ARGs ){
String STR = "ABC ";
System. Out. println (reverse (STR ));
}
Public static string reverse (string Str ){
Stack <character> stack = new stack <character> ();
Char CH = '';
String outstr = "";
For (INT I = 0; I <Str. Length (); I ++)
{
Ch = Str. charat (I );
Stack. Push (CH );
}
While (! Stack. isempty ())
{
Outstr + = stack. Pop ();
}
Return outstr;
}
}