StringBuilder sb = new StringBuilder("abcde");
System.out.println(sb.insert(2, sb));
~Sanjeev Singh<br />SCJP 1.5
-----------------------------------------------------------------------------
Originally written by David :
I suspect that one of the first things that the insert method does is count how many characters are going to be inserted, which in this case is going to be 5, the initial size of sb.
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
Originally written by David :
Since the insert method will only try and insert a finite number of characters it will not end up doing an infinite recursion.
-----------------------------------------------------------------------------
~Sanjeev Singh<br />SCJP 1.5
The characters of the CharSequence argument are inserted, in order, into this sequence at the indicated offset, moving up any characters originally above that position and increasing the length of this sequence by the length of the argument s.
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
~Sanjeev Singh<br />SCJP 1.5
Honk if you love justice! And honk twice for tiny ads!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|