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
Explain the meaning of java applet.
What is difference between Heap and Stack Memory?
How do you declare a variable?
What is called module?
What is ascii format?
Can a class have 2 constructors?
How do you read and print a string in java?
How can we create a thread in java?
What is busy spin, and why should you use it?
Why 1 is not a prime number?
Can there be an abstract method without an abstract class?
What is default constructors?
What is the parse method in java?
What is nested loop? What is dangling else condition in it?
What is the difference between Java and C++?