String
objects are immutable, meaning once a String
object is created, its value cannot be changed or modified.
String
will always create a new object instead.
String s1 = "Hello";
s1.concat(" World"); // Creates a new object, does not change s1
System.out.println(s1); // Output: Hello
String
Objects are Immutable?
String
objects are made immutable.
String
literal can be reused by different variables.
String
object at the same time.
HashMap
and HashSet
.
hashCode()
value is always constant.
HashMap
or HashSet
much faster and reliable.
Your feedback helps us grow! If there's anything we can fix or improve, please let us know.
Weโre here to make our tutorials better based on your thoughts and suggestions.