Java StringBuffer insert data

Introduction

To insert value in the middle of a StringBuffer, use the insert() method.

These are a few of its forms:

StringBuffer insert(int index, String str)  
StringBuffer insert(int index, char ch)  
StringBuffer insert(int index, Object obj) 

// Demonstrate insert().
public class Main {
  public static void main(String args[]) {
    StringBuffer sb = new StringBuffer("I demo2s.com!");

    sb.insert(2, "like ");
    System.out.println(sb);// www  .  j  a v  a2  s  .  c  o m
  }
}



PreviousNext

Related