Tagged articles
51 articles
Page 1 of 1
Tech Freedom Circle
Tech Freedom Circle
Jan 4, 2026 · Backend Development

Choosing Between String, StringBuilder, and StringBuffer for Concatenating 100 Million Strings in a JD Interview

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.

Stringconcurrencygc
0 likes · 44 min read
Choosing Between String, StringBuilder, and StringBuffer for Concatenating 100 Million Strings in a JD Interview
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Dec 22, 2025 · Fundamentals

Why Is StringBuilder Faster Than StringBuffer? Understanding Java’s Mutable vs Immutable Strings

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
Why Is StringBuilder Faster Than StringBuffer? Understanding Java’s Mutable vs Immutable Strings
macrozheng
macrozheng
May 23, 2025 · Fundamentals

Why ‘+’ Can Outperform StringBuilder in Java: Real Benchmarks Explained

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
Why ‘+’ Can Outperform StringBuilder in Java: Real Benchmarks Explained
macrozheng
macrozheng
Aug 7, 2024 · Fundamentals

Why ‘+’ Can Beat StringBuilder in Java: Benchmarks and Best Practices

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
Why ‘+’ Can Beat StringBuilder in Java: Benchmarks and Best Practices
Java Architect Essentials
Java Architect Essentials
Jun 16, 2024 · Backend Development

Performance Comparison of String Concatenation Using '+' Operator vs StringBuilder in Java

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
Performance Comparison of String Concatenation Using '+' Operator vs StringBuilder in Java
Top Architect
Top Architect
Feb 4, 2024 · Backend Development

Performance Comparison of String Concatenation Using '+' Operator vs StringBuilder in Java

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.

BackendJUnitstring-concatenation
0 likes · 8 min read
Performance Comparison of String Concatenation Using '+' Operator vs StringBuilder in Java
FunTester
FunTester
Dec 6, 2023 · Backend Development

Groovy Script setLength Error with StringBuilder and How to Work Around It

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
Groovy Script setLength Error with StringBuilder and How to Work Around It
Programmer DD
Programmer DD
Sep 25, 2023 · Backend Development

Discover Java 21’s New repeat() Method for StringBuilder and StringBuffer

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
Discover Java 21’s New repeat() Method for StringBuilder and StringBuffer
Architect's Guide
Architect's Guide
Apr 15, 2023 · Backend Development

Understanding Java String Concatenation, StringBuilder, and JVM Object Creation

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.

JVMJavaperformance
0 likes · 9 min read
Understanding Java String Concatenation, StringBuilder, and JVM Object Creation
Code Ape Tech Column
Code Ape Tech Column
Nov 1, 2022 · Backend Development

Performance Optimization of Template Variable Replacement in Alipay Card Package

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.

Backend DevelopmentJavaPerformance Optimization
0 likes · 8 min read
Performance Optimization of Template Variable Replacement in Alipay Card Package
macrozheng
macrozheng
Sep 22, 2022 · Backend Development

How Switching to StringBuilder Made Template Rendering 10× Faster

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.

JavaPerformance OptimizationTemplate Engine
0 likes · 11 min read
How Switching to StringBuilder Made Template Rendering 10× Faster
Cognitive Technology Team
Cognitive Technology Team
Sep 12, 2022 · Backend Development

Using Java Text Blocks to Simplify Multi‑line String Literals

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
Using Java Text Blocks to Simplify Multi‑line String Literals
Alibaba Cloud Developer
Alibaba Cloud Developer
Sep 8, 2022 · Backend Development

Boosting Template Rendering 10×: Replace String.replace with StringBuilder

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.

JavaPerformance OptimizationTemplate Rendering
0 likes · 9 min read
Boosting Template Rendering 10×: Replace String.replace with StringBuilder
Xuanwu Backend Tech Stack
Xuanwu Backend Tech Stack
Aug 3, 2022 · Fundamentals

Why Is Java String Immutable? Understanding Final, Thread Safety, and Performance

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.

JavaStringimmutability
0 likes · 5 min read
Why Is Java String Immutable? Understanding Final, Thread Safety, and Performance
Programmer DD
Programmer DD
Oct 26, 2021 · Backend Development

Which Java String Concatenation Method Is Fastest? A Performance Comparison

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
Which Java String Concatenation Method Is Fastest? A Performance Comparison
Programmer DD
Programmer DD
Sep 18, 2021 · Backend Development

Boost Java App Performance: 9 Practical Optimization Tips

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.

JavaProfilingbest practices
0 likes · 11 min read
Boost Java App Performance: 9 Practical Optimization Tips
Architect's Tech Stack
Architect's Tech Stack
Aug 12, 2021 · Fundamentals

Understanding and Implementing Java's StringJoiner: Source Code Analysis and Custom Usage

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.

BackendJavaStringJoiner
0 likes · 9 min read
Understanding and Implementing Java's StringJoiner: Source Code Analysis and Custom Usage
Selected Java Interview Questions
Selected Java Interview Questions
Apr 5, 2021 · Backend Development

Understanding Thread Safety in Java: StringBuilder, StringBuffer, and Servlets

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.

Backend DevelopmentJavaServlet
0 likes · 10 min read
Understanding Thread Safety in Java: StringBuilder, StringBuffer, and Servlets
Architect's Tech Stack
Architect's Tech Stack
Feb 22, 2021 · Backend Development

Understanding Java's StringJoiner Implementation and Usage

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
Understanding Java's StringJoiner Implementation and Usage
Su San Talks Tech
Su San Talks Tech
Feb 14, 2021 · Fundamentals

7 Common Java String Pitfalls and How to Avoid Them

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.

BigDecimalCode reviewMyBatis
0 likes · 13 min read
7 Common Java String Pitfalls and How to Avoid Them
Top Architect
Top Architect
Feb 12, 2021 · Backend Development

Performance Comparison of String and StringBuilder in Java Loops

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.

/loopBenchmarkJava
0 likes · 8 min read
Performance Comparison of String and StringBuilder in Java Loops
macrozheng
macrozheng
Dec 2, 2020 · Fundamentals

Master Java’s StringJoiner: Clean, Efficient String Concatenation

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
Master Java’s StringJoiner: Clean, Efficient String Concatenation
Architect's Tech Stack
Architect's Tech Stack
Nov 27, 2020 · Backend Development

When Does Java Use StringBuilder for String Concatenation?

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.

Compiler OptimizationJavaJavap
0 likes · 3 min read
When Does Java Use StringBuilder for String Concatenation?
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Oct 29, 2020 · Backend Development

Java Performance Optimization: Practical Tips and Best Practices

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.

JavaProfilingoptimization
0 likes · 10 min read
Java Performance Optimization: Practical Tips and Best Practices
Senior Brother's Insights
Senior Brother's Insights
Sep 15, 2020 · Fundamentals

Why Is StringBuilder Not Thread‑Safe? Deep Dive into Java’s Internals

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.

JVMJavaconcurrency
0 likes · 7 min read
Why Is StringBuilder Not Thread‑Safe? Deep Dive into Java’s Internals
Programmer DD
Programmer DD
Jul 26, 2020 · Backend Development

When Does Java Use StringBuilder for String Concatenation? A Deep Dive

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.

Compiler OptimizationJVMString concatenation
0 likes · 4 min read
When Does Java Use StringBuilder for String Concatenation? A Deep Dive
JavaEdge
JavaEdge
Jul 7, 2020 · Backend Development

Why Your Java Loops Waste Memory and How to Fix StringBuilder Usage

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
Why Your Java Loops Waste Memory and How to Fix StringBuilder Usage
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Jun 13, 2020 · Fundamentals

Understanding Java String, StringBuilder, and StringBuffer

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.

Stringimmutabilitystringbuffer
0 likes · 16 min read
Understanding Java String, StringBuilder, and StringBuffer
Architecture Digest
Architecture Digest
Dec 11, 2019 · Fundamentals

Understanding Java String Concatenation, Constant Pool, and Bytecode Behavior

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 PoolJavaMemory Management
0 likes · 12 min read
Understanding Java String Concatenation, Constant Pool, and Bytecode Behavior
ITPUB
ITPUB
Feb 9, 2019 · Backend Development

Why Java’s replaceFirst Slowed My Middleware to 10‑Second SQL Delays

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.

BackendDebuggingmiddleware
0 likes · 11 min read
Why Java’s replaceFirst Slowed My Middleware to 10‑Second SQL Delays
Programmer DD
Programmer DD
Jan 22, 2019 · Backend Development

Why Your Java String Concatenation Is Slowing Down and How to Fix It

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
Why Your Java String Concatenation Is Slowing Down and How to Fix It
Java Captain
Java Captain
Dec 22, 2018 · Fundamentals

Why Printing a Null Object in Java Does Not Throw an Exception

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.

Printingfundamentalsnull pointer
0 likes · 7 min read
Why Printing a Null Object in Java Does Not Throw an Exception
Java Captain
Java Captain
Mar 2, 2018 · Fundamentals

Understanding Java String, StringBuilder, and StringBuffer: Differences, Performance, and Interview Questions

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.

JavaMemoryString
0 likes · 16 min read
Understanding Java String, StringBuilder, and StringBuffer: Differences, Performance, and Interview Questions
Java Captain
Java Captain
Dec 25, 2017 · Fundamentals

Why Printing a null Object in Java Does Not Throw an Exception

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 sourcePrintStreamnull handling
0 likes · 7 min read
Why Printing a null Object in Java Does Not Throw an Exception
Qunar Tech Salon
Qunar Tech Salon
Mar 20, 2016 · Fundamentals

Converting Primitive Types to String and Efficient String Concatenation in Java

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
Converting Primitive Types to String and Efficient String Concatenation in Java