JAVA program for StringBuffer method insert()
This JAVA program is to insert a character at the specified index using StringBuffer method insert().
In StringBuffer method insert(int, char) inserts character passed at the specified index.
Program
import java.util.*; class sb6 { public static void main(String args[]) { String str; Scanner sc = new Scanner(System.in); System.out.println("Enter the string"); str = sc.nextLine(); StringBuffer s = new StringBuffer(str); s.insert(3,'t'); System.out.println("The character('t') is inserted at index(3) = "+s); } }