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 are parameters in a method?
What environment variables do I need to set on my machine in order to be able to run java programs?
What are streams in java 8?
What is the use of singleton?
Why stringbuilder is not thread safe?
In the below example, what will be the output?
What is boolean example?
what is meant by HQL?
Can memory leak in java?
What is double word?
What are the drawbacks of reflection?
Do we have pointers in java?
What is the byte range?
Is java hard to learn?
What is blank final variable?