Without going through the char sequence is there any way to reverse String
in Java
Use StringBuilder's
or StringBuffer's
method... reverse()
public class StringReverse
{
public static void main(String[] args)
{
String string=args[0];
String reverse = new StringBuffer(string).reverse().toString();
System.out.println("\nString before reverse: "+string);
System.out.println("String after reverse: "+reverse);
}
}
StringBuffer
is thread-safe, where as StringBuilder
is Not thread safe..... StringBuilder
was introduced from Java 1.5, as to do those operations faster which doesn't have any Concurrency to worry about....