- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Remove substring from StringBuilder in Java
In order to remove a substring from a Java StringBuilder Object, we use the delete() method. The delete() method removes characters in a range from the sequence. The delete() method has two parameters, start, and end. Characters are removed from start to end-1 index.
Declaration − The java.lang.StringBuilder.delete() method is declared as follows −
public StringBuilder delete(int start,int end)
Let us see an example which removes a substring from a StringBuilder.
Example
public class Example { public static void main(String[] args) { StringBuilder sb = new StringBuilder("Welcome to Java Programming"); System.out.println("Original StringBuilder Object: " + sb.toString()); sb.delete(4,10); System.out.println("New StringBuilder Object: " + sb.toString()); } }
Output
Original StringBuffer Object: Welcome to Java Programming New StringBuffer Object: Welc Java Programming
- Related Articles
- Java StringBuilder class.
- Minimum steps to remove substring 010 from a binary string in C++
- Converting String to StringBuilder in Java
- Constructors of StringBuilder class in Java.
- Methods of StringBuilder class in Java.
- Converting a StringBuilder to String in Java
- Difference between StringBuilder and StringBuffer in Java
- Remove value from HashMap in Java
- How do I remove a substring from the end of a string in Python?
- C# program to remove characters starting at a particular index in StringBuilder
- Java String, StringBuffer and StringBuilder Tutorial.
- Remove specified element from HashSet in Java
- Remove all values from TreeMap in Java
- Remove specified element from TreeSet in Java
- Remove all elements from TreeSet in Java

Advertisements