- 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
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
Advertisements
To Continue Learning Please Login
Login with Google