SlideShare a Scribd company logo
Java String, StringBuffer and
StringBuilder
Sujit Kumar
Zenolocity LLC
Copyright @
Mutability
• String is immutable – cannot change once it
has been created.
• StringBuffer is mutable.
• StringBuilder is mutable.
Thread Safety
• StringBuffer is thread-safe => all methods are
synchronized.
• StringBuilder is NOT thread-safe.
• Slight performance overhead with using
StringBuffer class as compared to using the
StringBuilder class.
When to use each?
• Use String if you require immutability
• Use StringBuffer if you need mutability and
thread-safety.
• Use StringBuilder if you need mutability but
no thread-safety but better performance.

More Related Content

PPTX
OO relationships between classes
PPTX
More about java strings - Immutability and String Pool
PPTX
Java strings
PPTX
Java final keyword
PPTX
Introduction to OOP with java
PPTX
SFDC Database Basics
PPTX
SFDC Database Security
PPTX
SFDC Social Applications
OO relationships between classes
More about java strings - Immutability and String Pool
Java strings
Java final keyword
Introduction to OOP with java
SFDC Database Basics
SFDC Database Security
SFDC Social Applications

More from Sujit Kumar (20)

PPTX
SFDC Other Platform Features
PPTX
SFDC Outbound Integrations
PPTX
SFDC Inbound Integrations
PPTX
SFDC UI - Advanced Visualforce
PPTX
SFDC UI - Introduction to Visualforce
PPTX
SFDC Deployments
PPTX
SFDC Batch Apex
PPTX
SFDC Data Loader
PPTX
SFDC Advanced Apex
PPTX
SFDC Introduction to Apex
PPTX
SFDC Database Additional Features
PPTX
Introduction to SalesForce
PPTX
Hibernate First and Second level caches
PPTX
Java equals hashCode Contract
PPTX
Java Comparable and Comparator
PPTX
Java build tools
PPTX
Java Web services
PPTX
Introduction to Spring
PPT
Java Web Development Course
PPTX
Unit testing principles
SFDC Other Platform Features
SFDC Outbound Integrations
SFDC Inbound Integrations
SFDC UI - Advanced Visualforce
SFDC UI - Introduction to Visualforce
SFDC Deployments
SFDC Batch Apex
SFDC Data Loader
SFDC Advanced Apex
SFDC Introduction to Apex
SFDC Database Additional Features
Introduction to SalesForce
Hibernate First and Second level caches
Java equals hashCode Contract
Java Comparable and Comparator
Java build tools
Java Web services
Introduction to Spring
Java Web Development Course
Unit testing principles
Ad

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Cloud computing and distributed systems.
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPT
Teaching material agriculture food technology
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Advanced IT Governance
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
cuic standard and advanced reporting.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Cloud computing and distributed systems.
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Teaching material agriculture food technology
Advanced Soft Computing BINUS July 2025.pdf
Modernizing your data center with Dell and AMD
Chapter 3 Spatial Domain Image Processing.pdf
Spectral efficient network and resource selection model in 5G networks
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
NewMind AI Monthly Chronicles - July 2025
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Advanced IT Governance
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
cuic standard and advanced reporting.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
MYSQL Presentation for SQL database connectivity
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Ad

String, StringBuffer and StringBuilder

  • 1. Java String, StringBuffer and StringBuilder Sujit Kumar Zenolocity LLC Copyright @
  • 2. Mutability • String is immutable – cannot change once it has been created. • StringBuffer is mutable. • StringBuilder is mutable.
  • 3. Thread Safety • StringBuffer is thread-safe => all methods are synchronized. • StringBuilder is NOT thread-safe. • Slight performance overhead with using StringBuffer class as compared to using the StringBuilder class.
  • 4. When to use each? • Use String if you require immutability • Use StringBuffer if you need mutability and thread-safety. • Use StringBuilder if you need mutability but no thread-safety but better performance.