answersLogoWhite

0


Best Answer

Strings are extremely useful but at the same time resource intensive too. In programs where numerous strings are used which need to be altered every now and then, it is advisable to use the StringBuffer or the StringBuilder class.

The java.lang.StringBuffer and java.lang.StringBuilder classes should be used when you have to make a lot of modifications to strings of characters. As we discussed in the previous chapter, String objects are immutable, so if you choose to do a lot of manipulations with String objects, you will end up with a lot of abandoned String objects in the String pool. On the other hand, objects of type StringBuffer and StringBuilder can be modified over and over again without leaving behind a great list of discarded String objects.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

The String class in Java is immutable, which means that once it's been set, its contents cannot be changed without allocating an entirely new object. This is bad for any programs which do a lot of string manipulation or concatenation.

In order to deal with this problem, two classes were created: StringBuilder and StringBuffer. Both of these classes will allow efficient changes of a string without all the extra memory overhead. The difference is that StringBuffer is thread-safe, while StringBuilder is not.

If you will have multiple threads changing the contents of your string at once, then StringBuffer is the class for you.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the use of string buffer class?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

C plus plus library functions for string operations?

You can use "string" class in C++ for string operations or you may use c style string functions as well. #include <string> String class in C++ provides all basic function to operate on strings. you may details descriptin at http://www.cplusplus.com/reference/string/string/


Definition of buffer in assembly language?

its just like a string of c++


How objects are predefind types?

An object is created from a class, like a house made from a blueprint. The object will therefore be of the type of its class. For instance, a String object will be of type String, which is defined by the String class.


Is string a standard java class?

No. A String is handled as an Object. In many cases you can treat it as primitive (and forget that it is an object), but sometimes the difference is relevant. The class is called String - note that it starts with an uppercase "S".One case where it is important to know that a String is an object is when comparing strings. You can't simply use the ==operator; instead, you have to use the .equals()method.No. A String is handled as an Object. In many cases you can treat it as primitive (and forget that it is an object), but sometimes the difference is relevant. The class is called String - note that it starts with an uppercase "S".One case where it is important to know that a String is an object is when comparing strings. You can't simply use the ==operator; instead, you have to use the .equals()method.No. A String is handled as an Object. In many cases you can treat it as primitive (and forget that it is an object), but sometimes the difference is relevant. The class is called String - note that it starts with an uppercase "S".One case where it is important to know that a String is an object is when comparing strings. You can't simply use the ==operator; instead, you have to use the .equals()method.No. A String is handled as an Object. In many cases you can treat it as primitive (and forget that it is an object), but sometimes the difference is relevant. The class is called String - note that it starts with an uppercase "S".One case where it is important to know that a String is an object is when comparing strings. You can't simply use the ==operator; instead, you have to use the .equals() method.


Why you should use StringBuilder class compared to String class?

Both StringBuffer and StringBuilder are much faster when compared to the String class when it comes to manipulating string objects. But, the StringBuilder is usually faster than the StringBuffer because the StringBuffer object is internally synchronized so, due to the multi-threading overhead the StringBuilder is faster. So, if your application is multi-threaded and the object could be accessed/modified by multiple threads use the StringBuffer, else use the StringBuilder.

Related questions

What is the difference among string and string buffer and string builder?

String is the immutable class that means the object f that class never be changed. String is the Sequence of character.


What is the user of stringbufer class explain how it is different from a string class?

A StringBuffer is similar to a String with a few differences:String objects are immutable while StringBuffer objects can be modifiedIf your code involves string manipulation, string buffer is faster than strings


What is string buffer in java?

StringBuffer is java class available in java.lang package which provides mutable String object where String is immutable class. The methods of this class like reverse(), append(),insert() gives facility to insert data of the same object.


C plus plus library functions for string operations?

You can use "string" class in C++ for string operations or you may use c style string functions as well. #include <string> String class in C++ provides all basic function to operate on strings. you may details descriptin at http://www.cplusplus.com/reference/string/string/


Definition of buffer in assembly language?

its just like a string of c++


What are some differences between String and StringBuffer in Java?

A String in Java refers to an immutable object that holds alphanumeric values. Everytime you try to modify the value held inside the String, a new object would be created.A StringBuffer refers to an object that is built to hold alphanumeric values for modification. StringBuffers were built for handling strings that need to be modified.Functionality wise both of them are similar.StringBuffer is mutable and faster with string manipulation operations, whereas Strings are immutable and are slower than StringBuffer for string operations.1) String objects are constants and immutable whereas StringBuffer does not2) String class supports constant strings. whereas String Buffer class supports growable and modified string3) Strings once we created we cannot modify them. whereas String Buffer objects after creation also can be able to delete to append any characters to it


What is string class features in java?

String class is useful to accept inputs from commands prompt as string arguments


Is String are instances of the class string?

yes


Define class string and implement all the functions related to strings?

define class string


What is the difference between string and class?

A string is a specific class that is used for dealing with text data


How objects are predefind types?

An object is created from a class, like a house made from a blueprint. The object will therefore be of the type of its class. For instance, a String object will be of type String, which is defined by the String class.


Is string a standard java class?

No. A String is handled as an Object. In many cases you can treat it as primitive (and forget that it is an object), but sometimes the difference is relevant. The class is called String - note that it starts with an uppercase "S".One case where it is important to know that a String is an object is when comparing strings. You can't simply use the ==operator; instead, you have to use the .equals()method.No. A String is handled as an Object. In many cases you can treat it as primitive (and forget that it is an object), but sometimes the difference is relevant. The class is called String - note that it starts with an uppercase "S".One case where it is important to know that a String is an object is when comparing strings. You can't simply use the ==operator; instead, you have to use the .equals()method.No. A String is handled as an Object. In many cases you can treat it as primitive (and forget that it is an object), but sometimes the difference is relevant. The class is called String - note that it starts with an uppercase "S".One case where it is important to know that a String is an object is when comparing strings. You can't simply use the ==operator; instead, you have to use the .equals()method.No. A String is handled as an Object. In many cases you can treat it as primitive (and forget that it is an object), but sometimes the difference is relevant. The class is called String - note that it starts with an uppercase "S".One case where it is important to know that a String is an object is when comparing strings. You can't simply use the ==operator; instead, you have to use the .equals() method.