A
Amit Jain
How can I reverse a given string without using String or StringBuffer
class method.
class method.
Amit Jain said:How can I reverse a given string without using String or StringBuffer
class method.
Lasse Reichstein Nielsen said:1. Why would you?
How can I reverse a given string without using String or StringBuffer
class method.
What is the sound of one hand clapping?Amit said:How can I reverse a given string without using String or StringBuffer
class method.
Amit said:How can I reverse a given string without using String or StringBuffer
class method.
Daniel said:What is the sound of one hand clapping?
If you already have a string, you can *print* the reverse if it by
counting backward from the end of it, and printing each character along
the way.
new StringBuilder( givenString ).reverse().toString();
I think the intent of the exercise is to solve it without using a
built-in reverse method. The prof wants his students to do a simple
char by char string building exercise.
Walter said:The standard recursive and fun way to do this is (in pseudo-code)
if length of string is 1, return string
else
return reverse(string without first character) joined with first
character
Amit Jain said:How can I reverse a given string without
using String or StringBuffer class method.
Roedy said:I think the intent of the exercise is to solve it without using a
built-in reverse method. The prof wants his students to do a simple
char by char string building exercise.
I think the intent of the exercise is to solve it without using a
built-in reverse method. The prof wants his students to do a simple
char by char string building exercise.
Piotr Kobzda said:new StringBuilder( givenString ).reverse().toString();
Amit said:for example i have string
String temp = "Java";
and I need some sort of code which reverse this string without using
any String or other class method
First: In Java, Strings are immutable. You cannot reverse a String.Amit said:for example i have string
String temp = "Java";
and I need some sort of code which reverse this string without using
any String or other class method
Amit said:How can I reverse a given string without using String or StringBuffer
class method.
Malinbeg said:String reverse (String in)
throws IOException
{
Reader reader = new StringReader(in);
Stack<Character> stack = new Stack();
Oops. "new Stack said:int ch;
while ((ch = reader.read()) != -1)
{
stack.push((char)ch);
}
Writer writer = new StringWriter();
while (!stack.isEmpty())
{
writer.write(stack.pop());
}
String reversed = writer.toString();
return reversed;
}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.