Java | StringBuilder Class

02 min read

StringBuilder Class:

  • Similar to StringBuffer class
  • But not synchronized (so, not thread-safe).
  • Faster performance.
  • In situations where mutable strings will be accessed by multiple threads and no external synchronization is provided, it is better to use StringBuffer than StringBuilder.
  • Constructor

StringBuilder( )

StringBuilder(String str)

  • Methods:

append( )

capacity( )

charAt( )

getChars( )

indexOf( )

lastIndex0f( )

insert( )

replace( )

reverse( )

toString( )

setCharAt( )

substring( )

POST A NEW COMMENT
     
  • Input (stdin)

    Output (stdout)


    Input (stdin)

    Your Output (stdout)

    Expected Output

    Compiler Message

    Input (stdin)

    2    3

    Your Output (stdout)

    5

    Expected Output

    5

    Compiler Message

    5

    Error