Can you please explain the difference between string, string buffer and string builder?

+1 vote
Hey,

The problem is every time I got confused with these three concepts . Can you please give me the proper idea about these three?

Thank you,
Jun 3 in Java by Sujoy
98 views

1 answer to this question.

+1 vote
String are immutable where as StringBuffer and StringBuilder are mutable.

StringBuffer is thread safe and syncronized whereas StringBuilder is not, thats why StringBuilder is faster as compared to StringBuffer.

String overrides equals() and hashCode() methods as the base class of String is Object.

For String manipulations in non-multi threaded environment, we should use StringBuilder else use StringBuffer class.
answered Jul 4 by Akash
• 160 points

Related Questions In Java

0 votes
2 answers

Please explain me the difference between scanner and the buffer reader?

As per your question for reading a ...READ MORE

answered Aug 27 in Java by Sirajul
• 39,140 points
103 views
0 votes
1 answer

Can you explain what is the difference between hashtable and hashmap?

Hi, Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for ...READ MORE

answered Aug 14 in Java by anonymous
57 views
0 votes
2 answers

What is the difference between string object and string literal?

A String literal is a Java language concept. This ...READ MORE

answered Aug 16 in Java by Sirajul
• 39,140 points
431 views
0 votes
2 answers

Can you give me the proper difference between java.util.Date vs java.sql.Date ?

The java.util.date class represents a particular moment in time, with ...READ MORE

answered Aug 27 in Java by Sirajul
• 39,140 points
134 views
0 votes
1 answer

What is the difference between main(String[] args) and main(String... args) in Java?

String[] is used to accept a single parameter ...READ MORE

answered Sep 6 in Java by Piya
57 views
0 votes
2 answers

What is the difference between implements and extends?

Extends : This is used to get attributes ...READ MORE

answered Aug 3, 2018 in Java by samarth295
• 2,190 points
636 views
0 votes
1 answer

Are arrays equivalent to objects in Java ?

Yes; the Java Language Specification writes: In the Java ...READ MORE

answered May 10, 2018 in Java by Rishabh
• 3,540 points
78 views
0 votes
1 answer

Remove objects from an array in Java?

We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,280 points
70 views
0 votes
1 answer

Performance difference of if/else vs switch statement in Java

The thing you are worried about is ...READ MORE

answered Jul 26, 2018 in Java by geek.erkami
• 2,640 points
532 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,190 points
606 views