1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
/* Java StringBuffer delete remove character or clear content Example This example shows how to delete or remove a particular character or clear entire content of a StringBuffer object. */ public class JavaStringBufferDeleteExample { public static void main(String[] args) { /* Java StringBuffer class following methods to delete / remove characters or claring the contents of a StringBuffer object. */ /* StringBuffer delete(int start, int end) remove the characters from start index to an end-1 index provided. This method can throw a StringIndexOutOfBoundException if the start index is invalid. */ StringBuffer sb1 = new StringBuffer("Hello World"); sb1.delete(0,6); System.out.println(sb1); /* To clear contents of a StringBuffer use delete(int start, int end) method in the below given way */ StringBuffer sb2 = new StringBuffer("Some Content"); System.out.println(sb2); sb2.delete(0, sb2.length()); System.out.println(sb2); /* StringBuffer deleteCharAt(int index) deletes the character at specified index. This method throws StringIndexOutOfBoundException if index is negative or grater than or equal to the length. */ StringBuffer sb3 = new StringBuffer("Hello World"); sb3.deleteCharAt(0); System.out.println(sb3); } } /* Output would be World Some Content ello World */ |
great! 😀
is there any method to find whitespaces in a string??
thx
how does this works with StringBuffer in java 6
public class Demo
{
public static void main(String[] args)
{
int x=4;
StringBuffer sb=new StringBuffer(“..fazba”);
sb.delete((x-3),(x-2));
System.out.println(sb);
}
}
what will be the output?? can anybody explain it???