[java] What is difference between mutable and immutable String in java

Java Strings are immutable.

In your first example, you are changing the reference to the String, thus assigning it the value of two other Strings combined: str + " Morning".

On the contrary, a StringBuilder or StringBuffer can be modified through its methods.

Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to string

How to split a string in two and store it in a field String method cannot be found in a main class method Kotlin - How to correctly concatenate a String Replacing a character from a certain index Remove quotes from String in Python Detect whether a Python string is a number or a letter How does String substring work in Swift How does String.Index work in Swift swift 3.0 Data to String? How to parse JSON string in Typescript

Examples related to immutability

Enums in Javascript with ES6 Correct way to push into state array What is difference between mutable and immutable String in java Const in JavaScript: when to use it and is it necessary? Aren't Python strings immutable? Then why does a + " " + b work? String is immutable. What exactly is the meaning? Immutable vs Mutable types Java Immutable Collections Set System.Drawing.Color values Remove specific characters from a string in Python

Examples related to mutable

What is difference between mutable and immutable String in java Immutable vs Mutable types What is the syntax for adding an element to a scala.collection.mutable.Map? Does the 'mutable' keyword have any purpose other than allowing the variable to be modified by a const function?

Examples related to stringbuffer

How to add an element at the end of an array? What is difference between mutable and immutable String in java Create a string with n characters What is the difference between String and StringBuffer in Java? Difference between StringBuilder and StringBuffer