StringBuffer insert() method in Java

In this tutorial, we will learn about StringBuffer insert() method in Java. StringBuffer class in Java provides insert() method to insert one string into another.It is overloaded to accept values of all the simple types, plus Strings, Objects, and CharSequences. Like append( ), it calls String.valueOf( ) to obtain the string representation of the value it is called with. This string is then inserted into the invoking StringBuffer object. These are a few of its forms:

Here, index specifies the index at which point the string will be inserted into…

Read More

StringBuffer append() method in Java

In this tutorial, we will learn about StringBuffer append() method in Java. StringBuffer class in Java provides append() method to append the String to the StringBuffer. The append( ) method concatenates the string representation of any other type of data to the end of the invoking StringBuffer object. It has several overloaded versions. Here are a few of its forms:

String.valueOf( ) method is called for each parameter to obtain its string representation. The result is appended to the current StringBuffer object. The buffer itself is returned by each version…

Read More

StringBuffer length() and capacity() method in Java

In this tutorial, we will learn about StringBuffer length() and capacity() method in Java. StringBuffer class in Java provides length() and capacity() methods. The current length of a StringBuffer can be found via the length( ) method, while the total allocated capacity can be found through the capacity( ) method. The syntax of these methods are as below: Syntax of length() method:

Returns: the length of the sequence of characters currently represented by this object. Syntax of capacity() method:

Returns: Returns the current capacity. The capacity is the amount…

Read More

StringBuffer deleteCharAt() method in Java

In this tutorial, we will learn about StringBuffer deleteCharAt() method in Java. StringBuffer in java is a thread-safe, mutable class. A Stringbuffer is same as String, the difference is that we can modify it. The String represents fixed-length, immutable character sequences. StringBuffer represents growable and writeable character sequences. We can append characters and substrings at the end or insert in the middle of StringBuffer using some methods in it. StringBuffer will automatically grow to make room for such additions and often has more characters pre-allocated than are actually needed, to…

Read More

StringBuffer reverse() method in Java

In this tutorial, we will learn about StringBuffer reverse() method in Java. StringBuffer in java is a thread-safe, mutable class. A Stringbuffer is same as String, the difference is that we can modify it. The String represents fixed-length, immutable character sequences. StringBuffer represents growable and writeable character sequences. We can append characters and substrings at the end or insert in the middle of StringBuffer using some methods in it. StringBuffer will automatically grow to make room for such additions and often has more characters pre-allocated than are actually needed, to…

Read More

StringBuffer substring() method in Java

In this tutorial, we will learn about StringBuffer substring() method in Java. Sometimes we might need to get substring out of a String in java. StringBuffer class in Java provides substring() method to get substring from a String. There are following two variants of substring() method in StringBuffer class.

This method returns a new String that contains a subsequence of characters currently contained in this character sequence. The substring begins at the specified index and extends to the end of this sequence. Parameters: start – The beginning index, inclusive.…

Read More

StringBuffer replace() method in Java

In this tutorial, we will learn about StringBuffer replace() method in Java. StringBuffer class in Java provides replace() method. This method can be used to replace the characters in a String with the specified String. You need to pass the start index, end index and the substring to replace the characters in the String. The substring begins at the specified start index and extends to the character at index end – 1 or to the end of the sequence if no such character exists. First the characters in the substring…

Read More

StringBuffer in Java

In this tutorial, we will learn about StringBuffer in Java. StringBuffer in java is a thread-safe, mutable class. A Stringbuffer is same as String, the difference is that we can modify it. The String represents fixed-length, immutable character sequences. StringBuffer represents growable and writeable character sequences. We can append characters and substrings at the end or insert in the middle of StringBuffer using some methods in it. StringBuffer will automatically grow to make room for such additions and often has more characters pre-allocated than are actually needed, to allow room…

Read More