Tagged articles
StringBuilder
58 articles · Page 1 of 1
This article explains Java String immutability, the hidden object creation behind '+' concatenation across JDK versions, StringBuilder and StringBuffer internals, constant pool behavior, and the invokedynamic optimization in JDK 9+, with bytecode examples and performance best practices.
Constant PoolJVMJava
0 likes · 16 min read

The article explains why Java's immutable String class can waste memory when concatenated, introduces the mutable StringBuilder class introduced in J2SE 5.0, demonstrates its usage with code examples comparing memory behavior, shows its length and capacity methods, and illustrates practical operations such as reverse and conversion between String and StringBuilder.
CodeExampleJavaMemoryManagement
0 likes · 7 min read

Java's String class is immutable and stored in a constant pool; the article explains the difference between == and equals, demonstrates common methods for inspection, transformation, splitting, and conversion, and shows best practices for concatenation with StringBuilder, thread‑safe StringBuffer, and newer utilities like join, repeat, format, and text blocks.
Equals vs ==JavaJava 8
0 likes · 10 min read

This article thoroughly examines Java's String, StringBuffer, and StringBuilder, explaining their internal implementations, immutability, JDK 9 changes, performance characteristics, and best‑practice usage scenarios, while providing concrete code examples, benchmarks, and interview questions to help developers choose the right tool.
InterviewJavaMemory
0 likes · 21 min read

This article explains the immutability of Java's String, compares the mutable StringBuilder and thread‑safe StringBuffer, provides performance benchmarks, and offers practical guidance on selecting the appropriate class for different coding scenarios, especially for interview preparation.
StringStringBufferStringBuilder
0 likes · 7 min read

This article breaks down the interview focus on Java's String, StringBuilder, and StringBuffer, explaining their mutability, thread‑safety, performance trade‑offs, core APIs, and best‑practice scenarios, while providing code examples and a concise comparison table for developers.
InterviewStringStringBuffer
0 likes · 9 min read

The article dissects a JD interview question about concatenating one hundred million strings, comparing String, StringBuilder, and StringBuffer, and explains how immutability leads to object explosion, how StringBuilder’s default capacity causes costly expansions, and why StringBuffer’s synchronized methods become a performance bottleneck in high‑concurrency scenarios.
ConcurrencyGCString
0 likes · 44 min read

The article shows that most Java performance problems stem from a simple, often‑overlooked mistake—using immutable String concatenation in loops, large text building, and logging—while demonstrating how StringBuilder, proper logging placeholders, and understanding the string pool can dramatically reduce GC pressure and CPU waste.
JavaLoggingString
0 likes · 8 min read

This article explains the fundamental differences between Java's String, StringBuilder, and StringBuffer—covering immutability, thread‑safety, internal caching mechanisms, and performance characteristics—while providing concrete code examples that illustrate how each class behaves in single‑threaded and multi‑threaded scenarios.
JavaStringStringBuffer
0 likes · 6 min read

This article dissects three high-frequency Java/SpringBoot interview questions—String vs StringBuffer vs StringBuilder, @SpringBootApplication annotation internals, and @Component with @Autowired for MyBatis Mapper—revealing underlying mechanisms, performance trade-offs, common pitfalls, and correct usage patterns to deepen technical understanding beyond rote memorization.
@Autowired@Component@SpringBootApplication
0 likes · 10 min read

This article explains how using the + operator for string concatenation in Java creates multiple immutable objects, why StringBuilder offers a memory‑efficient alternative, and analyzes two interview‑style code snippets with bytecode to reveal the exact number of objects each statement generates.
JVMJavaString Concatenation
0 likes · 9 min read

This article compares Java string concatenation using the '+' operator versus StringBuilder, showing that for simple cases '+' is equally fast and more concise, while in loops StringBuilder dramatically outperforms '+' due to reduced object creation overhead.
BenchmarkJUnitString Concatenation
0 likes · 8 min read

This article investigates the performance differences between Java’s ‘+’ operator, StringBuilder, and StringJoiner for string concatenation, presenting JUnit benchmark results for single and looped concatenations, analyzing compiled bytecode, and concluding when each method is optimal for readability and speed.
JUnitString ConcatenationStringBuilder
0 likes · 7 min read

This article investigates the performance differences between Java’s ‘+’ operator and StringBuilder for both simple and looped string concatenations, presenting JUnit benchmark results that show ‘+’ is comparable for single concatenations but significantly slower in loops, and recommends using the appropriate method based on context.
BenchmarkJavaString Concatenation
0 likes · 6 min read

This article examines Java string concatenation performance by comparing the '+' operator and StringBuilder in both simple and loop scenarios, presenting JUnit test results, bytecode analysis, and practical recommendations for choosing the most efficient approach.
BenchmarkJUnitJava
0 likes · 6 min read

This article examines the performance differences between using the '+' operator and StringBuilder for string concatenation in Java, presenting JUnit benchmark tests for simple concatenations and looped concatenations, analyzing compiled bytecode, and concluding that '+' is suitable for simple cases while StringBuilder excels in loops.
JUnitJavaString Concatenation
0 likes · 7 min read

This article explores Java String internals across JDK versions, explaining its memory representation, immutability, substring behavior, and how techniques like StringBuilder, intern(), and shared objects can dramatically reduce memory usage from gigabytes to megabytes in high‑scale applications.
InternJavaMemory Optimization
0 likes · 13 min read

This article examines Java string concatenation methods, presenting JUnit benchmarks that compare the '+' operator and StringBuilder in both single and loop scenarios, revealing that while simple concatenations perform similarly, loop concatenations are dramatically faster with StringBuilder, leading to practical recommendations.
BackendJUnitStringBuilder
0 likes · 8 min read


IT NiukeDec 27, 2023 · Backend Development
The article investigates IntelliJ IDEA's suggestion to replace StringBuilder with the '+' operator, showing that for simple concatenations the compiled code is identical and performance comparable, while in loops '+' becomes inefficient and StringBuilder remains preferable.
IntelliJ IDEAJUnitJava
0 likes · 8 min read

The article describes a Groovy scripting issue where calling StringBuilder.setLength(0) triggers a NoSuchMethodError, explains Groovy's automatic property generation, demonstrates debugging steps, metaprogramming attempts, and the final workaround that resolves the error.
DebuggingGroovyJava
0 likes · 6 min read

This article examines Java string concatenation performance, comparing the '+' operator and StringBuilder in both simple and loop scenarios, presenting JUnit benchmark results, bytecode analysis, and concluding that '+' is sufficient for single concatenations while StringBuilder excels in loops.
JavaString ConcatenationStringBuilder
0 likes · 7 min read

An empirical study compares Java string concatenation using the '+' operator versus StringBuilder, showing that for simple concatenations '+' is equally efficient and more concise, while in loops '+' incurs significant overhead, making StringBuilder the preferred choice for iterative concatenation.
BenchmarkJUnitJava
0 likes · 6 min read

Java 21 introduces repeat() overloads for StringBuilder and StringBuffer, allowing you to duplicate characters or CharSequence efficiently; the article demonstrates usage with sample code, explains the Unicode codePoint variant, and invites readers to explore creative applications of this new API.
Code ExampleJavaJava 21
0 likes · 2 min read

The article explains why using the '+' operator for string concatenation in Java creates many temporary objects, how the StringBuilder class and compile‑time optimizations can avoid this overhead, and demonstrates object‑creation counts for two typical interview questions using javap bytecode inspection.
BackendJavaJavap
0 likes · 10 min read

The article explains why using the '+' operator for string concatenation in Java creates multiple temporary objects, how the StringBuilder class and compiler optimizations like StringConcatFactory reduce memory overhead, and demonstrates object creation counts through interview‑style examples and javap bytecode analysis.
JVMJavaStringBuilder
0 likes · 9 min read

This article analyzes the original template‑variable replacement logic used in Alipay's card package, identifies costly String.replace operations, and presents five iterative optimizations—including removal of indexOf/substring, caching with Guava, and replacing String.replace with StringBuilder—that together achieve more than a ten‑fold speedup while discussing trade‑offs in readability and resource consumption.
CachingJavaStringBuilder
0 likes · 8 min read

An in‑depth case study of Alipay’s card‑coupon template engine reveals that replacing costly String.replace calls with a custom StringBuilder implementation, combined with caching strategies, can boost rendering performance by more than tenfold, while also reducing memory overhead and improving scalability.
CachingJavaStringBuilder
0 likes · 11 min read

The article explains how Java Text Blocks (the triple‑quote syntax) replace cumbersome string concatenation for embedding multi‑line SQL, JSON, or HTML, improving readability, eliminating most escape sequences, and behaving as regular String constants at compile and runtime.
Code TutorialJavaMultiline Strings
0 likes · 4 min read

By analyzing the Alipay card‑package template substitution logic, the author identified costly String.replace calls and iteratively applied five optimization versions—removing indexOf/substring, adding caching, and finally substituting StringBuilder for String.replace—achieving over tenfold performance gains and reduced resource consumption.
CachingJavaStringBuilder
0 likes · 9 min read

This article examines Java's String immutability, detailing how the final character array and private design prevent modification, compares mutable alternatives like StringBuilder and StringBuffer, and discusses their thread safety and performance implications to guide developers in choosing the appropriate class for different scenarios.
JavaStringStringBuffer
0 likes · 5 min read

This article compares five Java string‑concatenation techniques—‘+’, String.concat(), StringUtils.join(), StringBuffer.append() and StringBuilder.append()—through extensive timing tests from 100 to 900 000 iterations, revealing their speed, memory usage and best use cases for large‑scale data processing.
Apache CommonsJavaString Concatenation
0 likes · 11 min read

This article presents nine actionable Java performance‑optimization techniques—from avoiding premature tweaks and profiling bottlenecks to using StringBuilder, primitive types, and caching—complete with code examples and guidance on building a reliable test suite.
Best PracticesCachingJava
0 likes · 11 min read

This article examines why a dedicated StringJoiner helper class is useful, compares it with StringBuilder, explores rarely used features, and provides a detailed analysis of the JDK implementation—including member variables, constructors, add, toString, merge, length, and custom empty value handling—along with practical code examples.
BackendJavaStringBuilder
0 likes · 9 min read

This article explains why StringBuilder is not thread‑safe, demonstrates the problem with a multithreaded example that produces a wrong length and occasional ArrayIndexOutOfBoundsException, and shows how StringBuffer’s synchronized implementation avoids these issues.
ConcurrencyJavaStringBuffer
0 likes · 8 min read

This article explains why the StringJoiner class was introduced as a more flexible alternative to StringBuilder, details its internal fields, constructors, and core methods such as add, merge, toString, length, and setEmptyValue, and demonstrates their behavior with concrete Java code examples.
APICore LibraryJava
0 likes · 9 min read

This article explains why concatenating a null String with another string in Java produces the unexpected "nullhello world" output, debunks common misconceptions, and details the compiler's StringBuilder optimization, bytecode behavior, and related null‑handling mechanisms.
CompilerJavaNULL
0 likes · 6 min read

This article examines Java's StringJoiner class, explaining why it was introduced, how it builds on StringBuilder, detailing its constructors, methods such as add, merge, length, and toString, and provides code examples and analysis of its design choices and practical usage.
CodeAnalysisJDKJava
0 likes · 8 min read

This article explains the thread‑safety differences between StringBuilder and StringBuffer, demonstrates the problems of using mutable shared objects in multithreaded Java code, presents three solutions, and discusses why Servlets are not thread‑safe by default, highlighting visibility and ordering concepts.
ConcurrencyJavaServlet
0 likes · 10 min read

This article explains why the original StringBuilder is limited, demonstrates how to use StringJoiner for comma‑separated strings, and provides a detailed analysis of the JDK source code including member fields, constructors, element addition, toString, length, merge, and empty‑value handling.
BackendJDKJava
0 likes · 7 min read

This article walks through frequent Java string‑related mistakes—including misuse of replace vs replaceAll, Integer equality pitfalls, BigDecimal precision issues, StringBuilder versus String, isEmpty vs isBlank, MyBatis mapper null checks, and indexOf logic—providing clear explanations, code examples, and best‑practice recommendations.
MyBatisStringStringBuilder
0 likes · 13 min read

The article presents a series of Java benchmarks that compare per‑iteration and cumulative string concatenation using String versus StringBuilder, explains why the compiler optimises String concatenation to StringBuilder, and draws conclusions about the most efficient usage patterns in loop‑heavy code.
BenchmarkJavaLoop
0 likes · 8 min read

This article explains how Java 8’s StringJoiner simplifies concatenating delimited strings compared to StringBuilder/StringBuffer, covering basic usage, constructors, methods, prefix/suffix handling, empty value configuration, stream‑style chaining, and the related String.join() API with practical code examples.
JavaJava 8String
0 likes · 7 min read

This article investigates Java's string concatenation behavior, demonstrating through two examples why some concatenations invoke StringBuilder while others are optimized by the compiler, and explains the underlying bytecode differences revealed by decompiling with javap.
JavaJavapString Concatenation
0 likes · 3 min read

This article presents a collection of practical Java performance optimization techniques—including identifying bottlenecks, using profiling tools, writing performance tests, preferring StringBuilder, avoiding unnecessary object creation, and caching expensive resources—to help developers improve application speed and efficiency.
JavaStringBuilderoptimization
0 likes · 10 min read

Although StringBuilder and StringBuffer share similar APIs, StringBuilder lacks thread safety because its append method updates shared fields without synchronization, leading to race conditions that can corrupt the internal char array and cause ArrayIndexOutOfBoundsException, as demonstrated by a multithreaded test example.
ConcurrencyJVMJava
0 likes · 7 min read

This article examines why identical-looking string concatenations in Java sometimes use StringBuilder and other times are optimized away, showing bytecode differences, explaining compiler behavior, and summarizing the conditions that affect reference equality.
JVMString ConcatenationStringBuilder
0 likes · 4 min read


JavaEdgeJul 7, 2020 · Backend Development
The article explains how decompiled Java bytecode often reveals a new StringBuilder being created on each loop iteration, leading to unnecessary memory consumption, and shows how to replace implicit concatenation with explicit StringBuilder.append calls, chain them properly, and eliminate dead StringBuilder code.
CodeSmellJavaMemoryOptimization
0 likes · 3 min read

This article explains the internal implementation of Java's StringBuilder and StringBuffer, demonstrates how concurrent appends cause incorrect lengths and occasional ArrayIndexOutOfBoundsException, and shows why StringBuffer remains thread‑safe by using synchronized methods.
ConcurrencyJavaStringBuffer
0 likes · 7 min read

This article explains the immutable nature of Java's String class, compares it with mutable StringBuilder and thread‑safe StringBuffer, shows how the JVM handles string literals, constant pool, intern(), and provides performance guidelines and code examples for efficient string manipulation.
StringStringBufferStringBuilder
0 likes · 16 min read

This article explains how Java handles String literals and concatenation, detailing the roles of the String constant pool, the effects of the '+' operator invoking StringBuilder.append, the placement of resulting strings in the heap versus the pool, and demonstrates these concepts through bytecode analysis and code examples.
Constant PoolJavaString
0 likes · 12 min read

This tutorial explains how Scala treats strings as immutable Java objects, shows how to create and modify strings using literals, explicit types, and StringBuilder, demonstrates length retrieval, concatenation, formatted output, and provides a comprehensive list of java.lang.String methods usable in Scala.
ImmutableScalaString
0 likes · 14 min read


ITPUBFeb 9, 2019 · Backend Development
A detailed post walks through a mysterious 10‑second timeout on fast primary‑key SQLs in a sharding middleware, showing how log analysis, thread blocking, and an inefficient string‑replacement implementation caused the slowdown and how refactoring to StringBuilder restored performance.
BackendDebuggingStringBuilder
0 likes · 11 min read

This article examines how different Java string concatenation techniques impact performance, demonstrates compile‑time optimizations and bytecode generation, and provides practical recommendations—such as using StringBuilder—to avoid costly object creation inside loops.
JDKJavaJavap
0 likes · 8 min read

This article explains Java string concatenation methods—including the + operator, concat, StringBuilder, StringBuffer, and StringUtils.join—covers their underlying implementations, compares their performance, and provides practical recommendations for efficient and thread‑safe usage.
JavaString ConcatenationStringBuilder
0 likes · 9 min read

This article explains why Java's print methods output the literal "null" instead of throwing a NullPointerException, by examining the source code of PrintStream.print for both String and Object arguments, the behavior of String.valueOf, and the compiler‑generated StringBuilder handling of null during concatenation.
PrintingStringBuilderValueOf
0 likes · 7 min read

This article explains the internal implementation of Java's String class, compares it with StringBuilder and StringBuffer, demonstrates performance differences through benchmark code, and provides common interview questions with detailed answers, helping developers choose the appropriate class for various scenarios.
InterviewJavaMemory
0 likes · 16 min read

This article explores Java's handling of null references when printed or concatenated, showing how PrintStream.print and StringBuilder.append convert null values to the literal string "null" without raising exceptions, and walks through the underlying source code and bytecode.
JDK sourceNULL handlingPrintStream
0 likes · 7 min read

This article explains how to convert primitive types to strings in Java, discusses why simple concatenation with an empty string is inefficient, compares different splitting implementations, benchmarks various string concatenation methods including String.concat, the '+' operator, and StringBuilder, and recommends using String.valueOf and the OptimizeStringConcat JVM option for better performance.
StringString.concatStringBuilder
0 likes · 10 min read
