- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to insert a String into a Substring of StringBuffer
The insert() method of the StringBuffer class inserts the String starting from an index specified in the parameter along with the string
The syntax of the insert method is −
original_string.insert( index , var)
where var is the variable to be inserted and index is the position where the variable var is to be inserted.
Let us see an example program −
Example
public class Example { public static void main(String[] args) { StringBuffer str = new StringBuffer("Hello World"); String a = "Wonderful "; str.insert(6, a); System.out.println(str); } }
Output
Hello Wonderful World
- Related Articles
- Java Program to Insert a string into another string
- Golang program to insert a string into another string
- Insert a String into another String in Java
- Java Program to locate a substring in a string
- Java Program to Check if a string contains a substring
- Java program to insert a component into a JTextPane component
- Java program to convert a list of characters into a string
- Where to use a StringBuffer/StringBuilder than a String in Java?
- Java program to check if a Substring is present in a given String
- Java Program to Convert a String into the InputStream
- Golang program to check if a string contains a substring
- Java Program to Clear the StringBuffer
- Why should we use a StringBuffer instead of a String in Java?\n
- Golang Program to get a substring from the string
- How to insert a string in beginning of another string in java?

Advertisements