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

More from Sujit Kumar (20)

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

Recently uploaded (20)

PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
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.