Computer Science, asked by dsagarbariha, 10 months ago

what is stringbuffer in Java with example​

Answers

Answered by umaraligourgmailcom
0

Answer:

StringBuffer in java is used to create modifiable String objects. This means that we can use StringBuffer to append, reverse, replace, concatenate and manipulate Strings or sequence of characters. Corresponding methods under StringBuffer class are respectively created to adhere to these functions.

Explanation:

mark as brainlist pls

Answered by Oreki
1

A StringBuffer is like a String, but can be modified.

It contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.

It is synchronized i.e. thread safe. It means two threads can't call the methods of StringBuffer simultaneously.

Example:

public class Test {

  public static void main(String[ ] args) {

       StringBuffer sb = new StringBuffer("Hello");

       sb.append(" Java!");

       System.out.println("Modified - " + sb.toString( ));

       sb.reverse( );

       System.out.println("Reversed - " + sb.toString( ));

   }

}

Output:

Modified - Hello Java!

Reversed - !avaJ olleH

Similar questions