Java Data Type Tutorial - Java StringBuffer.insert(int offset, String str)








Syntax

StringBuffer.insert(int offset, String str) has the following syntax.

public StringBuffer insert(int offset,   String str)

Example

In the following code shows how to use StringBuffer.insert(int offset, String str) method.

//  w  w  w .  java  2s. c  o  m
public class Main {
  public static void main(String args[]) {
    StringBuffer buffer = new StringBuffer();


    String string = "java2s.com";    
    buffer.insert(0, string);
    

    System.out.println(buffer.toString());
    
  }
}

The code above generates the following result.