What is stringbuilder classes

Discussion in 'Programming' started by webmaster8757, Dec 8, 2009.

  1. #1
    I Don,t know about string builder classes.please help me by describing what is string builder classes and what are the use of string builder classes.
     
    webmaster8757, Dec 8, 2009 IP
  2. gacba

    gacba Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I am assuming you're referring to the java.lang.StringBuilder class now present in recent JDKs. That class is intended to replace code like this:
    
    String foo = "bar";
    foo += "bar2";
    foo += "bar3";
    foo += "bar4";
    
    Code (markup):
    which creates all sorts of temp strings in the generated bytecode, potentially creating inefficiencies. Although I'd say 90% of the time, that's overkill. But StringBuilder is used to do appends to an existing string with a dynamic buffer. If you're doing huge operations, you might benefit. Most of the time, probably not.
     
    gacba, Dec 8, 2009 IP