Primitive type vs Reference type
- Primitives are stored on stack while the other is on heap.
- Primitive types are mostly faster
- https://www.baeldung.com/java-primitives-vs-objects
BigDecimal vs Double
- BigDecimal requires more precision which consumes more resources
StringBuilder vs String literal
- StringBuilder always shows better performance
- If the String literals concatenation is in one line, JVM automatically optimizes it which results in the same performance as StringBuilder
- ex)
"Hello" + str1 + "World" + str2
almost equals toStringBuilder sb = new StringBuilder();sb.append("Hello");sb.append(str1);sb.append("World");sb.append(str2);
- ex)

Leave a comment