String objects are immutable in java

String objects are immutable in java. Explain how to create a string that can be changed

A string object that is created using “String” class is immutable. The characters of the object can not be changed / modified. There are some methods, such as split(), substring(), beginsWith() etc., modifies the strings, but returns ‘new strings’. The original string will remain same. The changes are made only for the newly returned string objects.

In order to change the ‘string’ (Object of String class), it must be sent as a parameter to the StringBuffer / StringBuilder constructor. This string will be converted into the object of StringBuffer or StringBuilder object. This is the only way to change the string, but not the String class object itself.
Can we pass a primitive type by reference in java? - Java
Primitive types can be passed by reference. 1. By storing the primitive type value in an array of single element and passing it...
What do you mean by the term signature in java?
A signature in java is a combination of elements in a list such as constructor and methods thereby distinguishing them from other constructors and methods...
Static nested class vs. a non-static one - Java
A static nested class can not directly access non-static methods or fields of an instance of its enclosing class...
Post your comment