-
Enhancement
-
Resolution: Duplicate
-
P3
-
None
-
1.1.4, 1.2.0
-
generic, sparc
-
generic, solaris_2.5.1
Name: mf23781 Date: 12/09/97
There is no method to remove characters from StringBuffer you have
to use a workaround which is much slower, adding the real methods
would make for better performance.
======================================================================
###@###.### (Feb 3, 1998):
Licensee brought up the same issue, now for JDK1.2 ->
Unfortunately there is no method to remove characters
from StringBuffer--you have to resort to the
following workaround code, which is much slower.
Adding the real methods would allow much faster code when
using StringBuffer.
a = new StringBuffer("The quick brown fox");
// workaround for a.delete(4,9);
String b = a.toString();
a.setLength(4);
a.append(b.substring(9,b.length()));
a = new StringBuffer("The quick brown fox");
// workaround for a.replace(4,9,"slow");
String c = a.toString();
a.setLength(4);
a.append("slow");
a.append(c.substring(9,c.length()));
API should be added to StringBuffer to fix this.
Evaluation from Sun:
It is often the case that .equals() should be redefined, but this
requires care. In the example with StringBuffer, redefining
.equals() at this point would change the semantics of any Hashtable
of StringBuffers that may have been created. Are two Stringbuffers equal
if they have the same characters but different capacity? There are many
useful notions of equality. Other folks may prefer the default object
equality.
If you want StringBuffers that redefine equality in the way you want, go
ahead and extend the Stringbuffer class to do what you want. It is not
possible to redefine the behavior of .equals() in class Dimension at
this late stage of deployment of JDK1.1; that would introduce a
incompatibility with existing code.
This defect has been closed with Sun.
SUNBUG: 4098031
It has been requested that this is considered for 1.2
- duplicates
-
JDK-4120694 StringBuffer should have more functionality
-
- Closed
-