Skip to content
Advertisement

Tag: stringbuffer

Why program did not show answer in out.txt?

The code should do a reverse and output the result to out.txt, but this does not happen, can you explain my mistake in the code. Thanks in advance Answer You are trying to reverse the string twice because of that the string is getting back to the original string. Also, there is an unnecessary (as per my understanding) while loop

If else condition with StringBuffer

I’m trying to make a If else condition to check if a current data exists on the database using a JSON request on a java application consuming a Rest Webservice. So, I want to receive a boolean or make a condition to verify what i’m receiving (normally, null or true/false) There’s a way to transform this in a boolean to

Most efficient way to concatenate Strings

I was under the impression that StringBuffer is the fastest way to concatenate strings, but I saw this Stack Overflow post saying that concat() is the fastest method. I tried the 2 given examples in Java 1.5, 1.6 and 1.7 but I never got the results they did. My results are almost identical to this Can somebody explain what I

String vs StringBuffer. Tip of IDEA

Intellij Idea offers to replace the following: To: As far as I know it’s less effective (mutable/immutable). So, what’s better? Answer The second one compiles to the same byte-code as the first one, except it uses a non-synchronized StringBuilder instead of a synchronized StringBuffer. So it’s not only much more readable, but also slightly faster. I’d choose the second one.

Advertisement