String is mutable or immutable?

Answers were Sorted based on User's Feedback



String is mutable or immutable?..

Answer / tanveer

String class is immutable .To make the String immutable use String Buffer or String Builder classes which are mutable

Is This Answer Correct ?    14 Yes 4 No

String is mutable or immutable?..

Answer / sumitpalsingh

String class is immutable .In String class we can not change or modify object value. To make an object value modifiable. we can use StringBuffer and StringBuilder classes.

Is This Answer Correct ?    7 Yes 0 No

String is mutable or immutable?..

Answer / 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

More Core Java Interview Questions

List some oops concepts in java?

0 Answers  


What is the difference between parameters and arguments ?

2 Answers  


Why java does not supports multiple inheritance?

3 Answers   TCS, VSoft,


What is the similarity between dynamic binding and linking?

0 Answers  


how can you say that java is independ language

2 Answers   TCS, Wipro,


These static constructors are correct ? class A { statc intA() { } static A(int x,int y) { } static A(int x) { } }

0 Answers   HCL,


Difference between ‘is-a’ and ‘has-a’ relationship in java?

0 Answers  


Which one of the following suits the description of a string better: derived or primitive?

0 Answers  


What is replacefirst in java?

0 Answers  


Which method will get invoked first in a stand alone application?

1 Answers  


What is the basic concept of java?

0 Answers  


What is the Scope of Static Variable?

0 Answers   Verifone,


Categories