Java-StringBuffer

StringBuffer The StringBuffer class is the companion class of the String class. The objects of the String class represent fixed-length, immutable character sequences. On the other hand, the objects of the StringBuffer class represent growable and mutable character sequences. The methods that are available in the StringBuffer class make it possible to insert a substring … Read more…

Java-Extracting Character

Extracting Character The charAt( ) method of StringBuffer class enables us to extract at the specified index position. For example, in the following program, the character at the index position ‘3’ in the string “ABCDE” is ‘D’, the output statement will return the character ‘D’. The setCharAt( ) method of StringBuffer class enables us to … Read more…

Java-Insert

Insert The insert( ) method is a companion method of the append( ) method. While the append( ) method enables us to add a new string only at the end of an existing string, the insert( ) method helps us to add a new string from any specified position in the existing string. For example, … Read more…

Java-Reverse and Replace

reverse You can reverse the characters with in a StrngBuffer object using reverse() method. This method returns the reversed object. replace You can replace one set of characters with another set inside a StringBuffer object by calling replace(int startIndex, int endIndex, String str). The substring being replaced is specified by the indexes startIndex and endIndex. Thus, … Read more…

Java-Get Substring

Get Substring A substring is a part of another string. For example, the strings “123” and “45” are substrings of the string “12345”. The subString( ) method of the StringBuffer class enables us to extract the substrings from a string. A substring( ) method of the form substring( int startIndex, int endIndex-1 ) will return … Read more…

Java-Appending Any Data Type

Appending Any Data Type The append( ) method concatenates the string representation of any other type of data to the end of the invoking SringBuffer object. Program Program Source public class Javaapp { public static void main(String[] args) { StringBuffer stbr = new StringBuffer(); String str = “1234”; char c = ‘5’; int in = … Read more…