Answer Posted / deep
String is neither immutable nor mutable, String is a class Lol.. and string objects are immutable cause you can't change the data which is stored inside in a object..
Let's take a example..
String a = "Dark Knight"; or String a = new String("Dark Knight");
now let's perform operation on String object..
there are some method you can perform on string object so i am gonna perform replace operation..
a.replace("Dark","Blue");
now try to display what's inside String object which is 'a'..
System.out.println(a); // Ans. Dark Knight
System.out.println(a.replace("Dark,"Blue"); // Ans. Blue Knight
but value inside string object is still Dark Knight so to get over this you have to create another object and you have to perform same action again..
String a = "Dark Knight" or String a = new String("Dark Knight");
String b = a.replace("Dark","Knight");
System.out.println(a); // Ans. Dark Knight
System.out.println(b); // Ans. Blue Knight
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What is consumer in java?
What are advantages of exception handling in java?
Is set thread safe java?
Explain public static void main(string args[]) in java.
what is abstract class in Java?
Can java list contain duplicates?
What are the different types of sorting in java?
What is meant by oops concept in java?
Is arraylist dynamic in java?
What is a nested class?
What is string data?
What is the output of the below java program?
Why is it important to initialize a variable?
Explain the concept of hashtables?
What is an example of a boolean?