java tutorial - Java StringBuffer insert() method - java programming - learn java - java basics - java for beginners



Java  stringbuffer insert

Learn Java - Java tutorial - Java stringbuffer insert - Java examples - Java programs

Description

The insert () method — in Java, inserts characters into this buffer string (StringBuffer). The substring is added before the specified index.

Syntax

The syntax of the method for each data type is:

public StringBuffer insert(int offset, boolean b)
public StringBuffer insert(int offset, char c)
public insert(int offset, char[] str)
public StringBuffer insert(int index, char[] str, 
                           int offset, int len)
public StringBuffer insert(int offset, float f)  
public StringBuffer insert(int offset, int i)
public StringBuffer insert(int offset, long l) 
public StringBuffer insert(int offset, Object obj) 
public StringBuffer insert(int offset, String str)
click below button to copy the code. By - java tutorial - team

Options

Detailed information about the parameters:

  • the parameter depends on what you are trying to insert.

Return value

  • In Java insert (), returns the modified StringBuffer object.

Sample Code

public class Test {
 public static void main(String args[]) {
      StringBuffer sb = new StringBuffer("wikchy");
      sb.insert(3,"ite");
      System.out.println(sb); 
   }  
}
click below button to copy the code. By - java tutorial - team

Output

wikitechy

Related Searches to Java StringBuffer insert() method