Version 1 is preferable because it is shorter and the compiler will in fact turn it into version 2 – no performance difference whatsoever.
More importantly given we have only 3
properties it might not make a
difference, but at what point do you
switch from concat to builder?
At the point where you’re concatenating in a loop – that’s usually when the compiler can’t substitute StringBuilder
by itself.
Related Contents:
- Java: String concat vs StringBuilder – optimised, so what should I do?
- String concatenation: concat() vs “+” operator
- When to use StringBuilder in Java [duplicate]
- String, StringBuffer, and StringBuilder
- Concatenating null strings in Java [duplicate]
- Why StringBuilder when there is String?
- Fastest way to iterate over all the chars in a String
- Should I use Java’s String.format() if performance is important?
- Is it better practice to use String.format over string Concatenation in Java?
- The concatenation of chars to form a string gives different results
- What is the difference between String and StringBuffer in Java?
- Which loop has better performance? Why?
- Performance penalty of String.intern()
- Garbage collection behaviour for String.intern()
- Why does appending “” to a String save memory?
- Correct way to use StringBuilder in SQL
- Java ‘+’ operator between Arithmetic Add & String concatenation? [duplicate]
- Fastest way to strip all non-printable characters from a Java String
- Why StringJoiner when we already have StringBuilder?
- Java split String performances
- Is there a memory-efficient replacement of java.lang.String?
- Java Array Searching [closed]
- How to get a string present within single quotes in a line using java [closed]
- Immutability of Strings in Java
- String replace method is not replacing characters
- What are all the escape characters?
- How to extract a substring using regex
- Regex to match a C-style multiline comment
- Java Strings: “String s = new String(“silly”);”
- String concatenation in Java – when to use +, StringBuilder and concat [duplicate]
- How to convert a char to a String?
- Java 8: performance of Streams vs Collections
- Strip Leading and Trailing Spaces From Java String
- How to convert a color integer to a hex String in Android?
- CharSequence VS String in Java?
- Difference between “char” and “String” in Java
- How to shuffle characters in a string without using Collections.shuffle(…)?
- How to remove single character from a String
- How to replace case-insensitive literal substrings in Java
- Closing a Scanner throws java.util.NoSuchElementException
- How to obtain the last path segment of a URI
- Android coding with switch (String)
- Scanner only reads first word instead of line
- Fatal Error: Invalid Layout of java.lang.String at value
- String replace a Backslash
- Find the Number of Occurrences of a Substring in a String
- Creating a UUID from a string with no dashes
- How is String in switch statement more efficient than corresponding if-else statement?
- String concatenation with Null
- Is it possible to force an existing Java application to use no more than x cores?