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
55 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
1 answer

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

BufferedReader is synchronous while Scanner is not.  BufferedReader ...READ MORE

answered Aug 2 in Java by sampriti
• 1,100 points
23 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
26 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
• 19,670 points
73 views
0 votes
1 answer

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

As per Javadoc java.sql.Date is a thin wrapper around millisecond ...READ MORE

answered Aug 2 in Java by sampriti
• 1,100 points
16 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
456 views
0 votes
1 answer

What is the difference between jdk and jre?

JRE: It stands for Java Runtime Environment. ...READ MORE

answered Apr 20, 2018 in Java by Akrati
• 3,150 points
118 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
52 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
42 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,320 points
352 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
269 views