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
How do you decide when to use arraylist and linkedlist?
Is array synchronized in java?
Which are the two subclasses under exception class?
what is daemon thread and which method is used to create the daemon thread? : Java thread
why Interface used?
Why is it called buffering?
Can you write a java class that could be used both as an applet as well as an application?
Explain importance of throws keyword in java?
Write an algorithm for quick sort?
When is the garbage collection used in Java?
Is empty .java file name a valid source file name?
What is array length in java?
Which java ide is used the most?
Explain hashset and its features?
How do you compare objects in java?