answersLogoWhite

0


Best Answer

The StringBuilder class was added in Java 5. It has exactly the same API as the StringBuffer class, except StringBuilder is not thread safe. In other words, its methods are not synchronized. Sun recommends that you use StringBuilder instead of StringBuffer whenever possible because StringBuilder will run faster. So apart from synchronization, anything we say about StringBuilder's methods holds true for StringBuffer's methods, and vice versa.

User Avatar

Wiki User

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

Wiki User

10y ago

StringBuilder is a mutable String. It is used when the String changes frequently.

This answer is:
User Avatar

Add your answer:

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

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.


String reverse program with single string and without using library functions in java?

You can create a separate string initially empty. Then using a loop, start at the end of the string and add it to the end of the other string. At the end of the loop, the other string would contain the reverse.


What is a stringbuilder and stringbuffer?

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.StringBuffer vs. StringBuilderThe StringBuilder class was added in Java 5. It has exactly the same API as the StringBuffer class, except StringBuilder is not thread safe. In other words, its methods are not synchronized. (For now just know that syncrhonized is used for thread safety and causes an overhead in terms of performance) Sun recommends that you use StringBuilder instead of StringBuffer whenever possible because StringBuilder will run faster. So apart from synchronization, anything we say about StringBuilder's methods holds true for StringBuffer's methods, and vice versa.


Can you declare an instance variable of class StringBuffer in Java program?

Here's how to create a StringBuffer instance.StringBuffer sb = new StringBuffer();sb.append("Add this is to the buffer");// ...Note the StringBuffer has synchronized methods so if it is only accessed in a single thread context then a StringBuilder is preferred. StringBuffer and StringBuilder both implement the Appendable and CharSequence interfaces so can be used interchangeably.


Write a Java program to convert a decimal no to binary?

Here's a simple Java method to perform the conversion from decimal to a binary string representation:public String toBinaryString(int n) {StringBuilder sb = new StringBuilder();while(n != 0) {sb.insert(0, n % 2 != 0 ? '1' : '0');n /= 2;}return sb.toString();}The java.lang.Integer class provides a conversion helper method between decimal (integer) and binary numbers in string form called toBinaryString().String binaryValue = Integer.toBinaryString(43) // 43-> "101011"

Related questions

Difference between stringbuffer and stringbuilder in java?

The StringBuilder class was added in Java 5. It has exactly the same API as the StringBuffer class, except StringBuilder is not thread safe. In other words, its methods are not synchronized. (For now just know that syncrhonized is used for thread safety and causes an overhead in terms of performance) Sun recommends that you use StringBuilder instead of StringBuffer whenever possible because StringBuilder will run faster. So apart from synchronization, anything we say about StringBuilder's methods holds true for StringBuffer's methods, and vice versa.


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.


String reverse program with single string and without using library functions in java?

You can create a separate string initially empty. Then using a loop, start at the end of the string and add it to the end of the other string. At the end of the loop, the other string would contain the reverse.


What is a stringbuilder and stringbuffer?

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.StringBuffer vs. StringBuilderThe StringBuilder class was added in Java 5. It has exactly the same API as the StringBuffer class, except StringBuilder is not thread safe. In other words, its methods are not synchronized. (For now just know that syncrhonized is used for thread safety and causes an overhead in terms of performance) Sun recommends that you use StringBuilder instead of StringBuffer whenever possible because StringBuilder will run faster. So apart from synchronization, anything we say about StringBuilder's methods holds true for StringBuffer's methods, and vice versa.


Can you declare an instance variable of class StringBuffer in Java program?

Here's how to create a StringBuffer instance.StringBuffer sb = new StringBuffer();sb.append("Add this is to the buffer");// ...Note the StringBuffer has synchronized methods so if it is only accessed in a single thread context then a StringBuilder is preferred. StringBuffer and StringBuilder both implement the Appendable and CharSequence interfaces so can be used interchangeably.


Write a Java program to convert a decimal no to binary?

Here's a simple Java method to perform the conversion from decimal to a binary string representation:public String toBinaryString(int n) {StringBuilder sb = new StringBuilder();while(n != 0) {sb.insert(0, n % 2 != 0 ? '1' : '0');n /= 2;}return sb.toString();}The java.lang.Integer class provides a conversion helper method between decimal (integer) and binary numbers in string form called toBinaryString().String binaryValue = Integer.toBinaryString(43) // 43-> "101011"


What is the fastest way to concat strings in aspnet?

stringbuilder


Can you use pointers in java?

Java does not support Pointers and hence you cannot use it in Java.


What technologies link to Java?

Java is exclusive to surfing the web. Some web sites use Java to embed videos, others use Java for advertisements.


Does Java Script use the same compiler as Java?

No


What you use in case of pointer in java?

Java does not have pointers


What is java 7?

Java 7 is the most current version of Java. Many movies and games use Java.