Daniel Pitts wrote:
> Amit Jain wrote:
>> How can I reverse a given string without using String or StringBuffer
>> class method.
>>
> What is the sound of one hand clapping?
Whoosh?
> 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.
That way some methods of String will still be used indirectly (when
allowed, I prefer my earlier suggestion).
The only way I know to achieve the result without touching any of String
methods is to reflectively access String's internals (i.e. value,
offset, and count fields). And then create a new String (we can use
constructors, they are not a methods) with the reversed chars of the
value array copy. That way is of course never guarantied to work, and
is rather awful hack than the solution. Thus, one should even try to do
that!
piotr