what is mutability?which one is mutable String or StringBuffer?and why?give
examples of each which shows the mutability of each String or StringBuffer
Answer Posted / rajender
if use
String s="raj";
here string object created in string content pool(scp).it
(scp)doesn't allow duplicate objects.so it is immutable
String s=s+"ramu";
here string object created in heap allows duplicate
objects.so it is immutable
in heap
String s=rajramu;
if use string buffer every time it will create object in
heap.heap allows duplicate object.so it is mutable
StringBuffer sb=new StringBuffer("raj");
StringBuffersb1=sb.append("ramu");
if u hav any questions related java just call me:9952942104
finally it create duplicate value in heap.
| Is This Answer Correct ? | 17 Yes | 10 No |
Post New Answer View All Answers
What is command line used for?
What are different types of inner classes ?
Give an example of call be reference significance.
How would you dynamically allocate memory to an array?
How do I print a “?
What is abstraction in java?
What is variable argument in java?
What do you understand by the term wrapper classes?
Are arrays classes in java?
How arrays are stored in memory in java?
What is the use of coding?
What will be the initial value of an object reference which is defined as an instance variable?
Does sprintf allocate memory?
Is java ee a framework?
How to compare two strings in java program?