---
title: "String, String Builder and String Buffer in Java"  
description: "In this article I am explaining about String, String Builder and String Buffer in Java"  
author: "Manoj Pandey"  
published: 2015-04-12  
updated: 2017-12-05  
canonical: https://www.mindstick.com/articles/1717/string-string-builder-and-string-buffer-in-java  
category: "java"  
tags: ["java"]  
reading_time: 3 minutes  

---

# String, String Builder and String Buffer in Java

Strings, which are widely used in Java programming, are a sequence of characters. In the Java [programming language](https://www.mindstick.com/articles/332896/top-5-programming-languages-for-ios-app-development), strings are objects.\

String text="Hello";

In string we can append character, [concatenate](https://www.mindstick.com/interview/1431/how-do-you-concatenate-strings-in-mysql) string, find character, and remove character in java. String is a group of character or array of character. For example, the string "Hello" may be backed by the array ['H', 'e', 'l', 'l', 'o'] with offset 0 and length 5. text=text.to UpperCase(); text=text.toLowerCase(); Output -: HELLO & hello

##### Concatenation of String

String text1=="Hello ";

String text2=="World";

text1=text1+text2; or

text1+=text2;

Output-: [Hello World](https://www.mindstick.com/forum/23190/why-does-this-code-using-random-strings-print-hello-world);

[StringBuffer](https://www.mindstick.com/forum/33775/search-for-a-stringbuffer-object-in-an-arraylist) a modifiable sequence of characters for use in creating strings. This class is intended as a direct [replacement](https://www.mindstick.com/forum/160229/timing-belt-replacement-cost-guide-everything-you-need-to-know) of StringBuffer for non-concurrent use; unlike StringBuffer this class is not synchronized.

Simply stated, objects of type String are read only and immutable. The StringBuffer class is used to represent characters that can be modified. The significant performance [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between these two classes is that StringBuffer is faster than String when performing simple concatenations.

A String is immutable, i.e. when it's created, it can never change. The significant performance difference between these two classes is that StringBuffer is faster than String when performing simple concatenations. In [String manipulation](https://www.mindstick.com/forum/159022/how-does-rust-handle-string-manipulation-and-what-is-the-difference-between-string-and-str-types) code, character strings are routinely concatenated.

StringBuffer buffer=new StringBuffer("Hello ");

buffer.append("World");

Output-: Hello World

[StringBuilder](https://www.mindstick.com/blog/99/stringbuilder-class-in-c-sharp) java.lang.StringBuilder class is mutable sequence of characters. This provides an API compatible with StringBuffer, but with no guarantee of synchronization.

StringBuilder builder = new StringBuilder("Hello ");

builder.append("World");

Output-: Hello World

##### Difference between StringBuffer and StringBuilder

##### \
· StringBuffer is synchronized, StringBuilder is not.

##### \
· StringBuilder is faster than StringBuffer because it's not synchronized.

##### \

· The StringBuilder class provides an API compatible with StringBuffer, but with

no guarantee of synchronization. The StringBuilder class is designed for use as a

drop-in replacement for StringBuffer in places where the string buffer was being

used by a single thread (as is generally the case). Where possible, it is

recommended that this class be used in preference to StringBuffer as it will be

faster under most implementations.

##### \
Here I am creating a sample of Reverse string using String and String butter

```
public class Demo {     public static void main(String args[]) {           String text;           StringBuffer sbuffer;           text = "Hello World";           String demo = "";// by unsing string           for (int i = text.length() - 1; i >= 0; i--) {                demo += text.charAt(i);            }// using StringBuffer           sbuffer = new StringBuffer(text);           System.out.println(demo);           System.out.println(sbuffer.reverse());      } }
```

Output-: dlroW olleH

dlroW olleH \

---

Original Source: https://www.mindstick.com/articles/1717/string-string-builder-and-string-buffer-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
