Home » Java programming language

Java StringBuffer delete(int spos , int epos) method with Example

Java StringBuffer delete(int spos , int epos) method: Here, we are going to learn about the delete(int spos , int epos) method of StringBuffer class with its syntax and example.
Submitted by Preeti Jain, on June 30, 2019

StringBuffer Class delete(int spos , int epos)

  • This method is available in package java.lang.StringBuffer.delete(int spos , int epos).
  • This method is used to delete all the characters lies between spos(Starting position) and epos(Ending position) in the method.
  • If StringBuffer object is empty then spos and epos are equal or same.

Syntax:

    StringBuffer delete(int spos , int epos){
    }

Parameter(s):

We can pass two objects in the method of the StringBuffer i.e starting position (spos) and ending position(epos).

Return value:

The return type of this method is StringBuffer that means this method returns a reference of the object.

Java program to demonstrate example of delete() method

import java.lang.StringBuffer;

public class StringBufferClass {
    public static void main(String[] args) {

        StringBuffer sb = new StringBuffer("Java is a programming language : ");

        // use delete(int spos , int epos) it will delete all characters 
        // lies between index1 and index2.

        // Display result after implementing delete(0,9)
        System.out.println("The result will be after implementing method delete(0,9) is :" + sb.delete(0, 9));

        sb = new StringBuffer("Java Support OOPS Concept");

        // use delete(int spos , int epos) it will delete all characters 
        // lies between spos and epos

        // Display result after implementing delete(17,25)
        System.out.println("The result will be after implementing method delete(17,25) is :" + sb.delete(17, 25));
    }
}

Output

D:\Programs>javac StringBufferClass.java
D:\Programs>java StringBufferClass
The result will be after implementing method delete(0,9) is : programming language :
The result will be after implementing method delete(17,25) is :Java Support OOPS





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.