Java StringBuffer example to delete a specific character at the given index using deleteCharAt


public StringBuffer deleteCharAt(int index)
Removes the char at the specified position in this sequence. This sequence is shortened by one char.
Note: If the character at the given index is a supplementary character, this method does not remove the entire character. If correct handling of supplementary characters is required, determine the number of chars to remove by calling Character.charCount(thisSequence.codePointAt(index)), where thisSequence is this sequence.

Program:
package com.candidjava;

public class StringBufferDeleteCharAt 
{
	public static void main(String args[]) 
	{
		StringBuffer s=new StringBuffer("Machismo");
		s.deleteCharAt(4);
		System.out.println("The newly characterised String is "+s);
	}
}

Output:
The newly characterised String is Machsmo

Description:
       The character 'i' at index 4 is being removed by the deleteCharAt function.

Parameters:
index - Index of char to remove

Returns:
This object.

Throws:
StringIndexOutOfBoundsException - if the index is negative or greater than or equal to length().


Related Post

Comments


©candidjava.com