Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4866323

(str) String{Buffer,Builder} should have clear()

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.4.2, 6
    • core-libs
    • x86
    • linux, windows_2000

      Name: rmT116609 Date: 05/19/2003


      A DESCRIPTION OF THE REQUEST :
      The java.util.Collection defines a clear() method to remove all elements, I know StringBuffer is not part of the collections framework, but it logical to include the clear() method in the StringBuffer class.

      I would expect the StringBuffer clear() method to be semantically equivalent to sb.delete(0, sb.length()) - where 'sb' is a StringBuffer instance - but be much more efficient.

      Specifically: the clear() function would remove all characters, but leave the capacity unchanged.

      Yes, I know I can create a new instance of StringBuffer or use setLength(0), but these are more obscure ways and/or less efficient ways of producing a cleared StringBuffer.

      JUSTIFICATION :
      Improve readability and efficiency of Java programs (not to mention reducing the irritation caused by going to use an 'obvious' method and finding it missing!).
      (Review ID: 186093)
      ======================================================================

            jgish Jim Gish (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: