0
I know the difference between stringBuffer and stringbuilder is that one is synchronized and one is not, and that both represent strings that can be changed, but what synchronized means in practice?
0
I know the difference between stringBuffer and stringbuilder is that one is synchronized and one is not, and that both represent strings that can be changed, but what synchronized means in practice?
0
Stringbuilder vs Stringbuffer
Both are much faster for concatenating values than the common string and do exactly the same function. The main difference is that Stringbuffer is synchronized, while the other one is not. Thus, you ensure the consistency of your code when there are several threads reading or modifying the same String. For these cases, the ideal is to use Stringbuffer.
But Stringbuilder is still faster than Stringbuffer.
Source: http://www.devmedia.com.br/diferencas-entre-string-stringbuilder-e-stringbuffer-em-java/29865
Your answer tells what he has already put in the question.
Thus, you ensure the consistency of your code when there are several threads reading or modifying the same String. For these cases, the ideal is to use Stringbuffer.
Browser other questions tagged java
You are not signed in. Login or sign up in order to post.
Damn, I was almost done with the answer when it was closed.
– Victor Stafusa
@Bigown is not really a duplicate. This question is about synchronization, which the other one doesn’t talk about. The other question is about the extra space that is allocated in the
StringBuffer
/StringBuilder
to improve performance. The question of synchronization is addressed only as an extra point in the utluiz answer - the remaining three answers say nothing about this.– Victor Stafusa
But the answer is there, it’s not?
– Maniero
@bigown Well, I will not vote to reopen anyway. But if it were not the answer of utluiz, I would certainly do it.
– Victor Stafusa
Yeah, if I didn’t have his answer, I wouldn’t be answering. If a search had been made with both names that answer would have been found and the question would not have been posted.
– Maniero
@Victorstafusa if the answer adds something, put there even if it is only as a complement.
– Maniero