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


Please Help Members By Posting Answers For Below Questions

Are there structures in java?

747


Can you explain inner class.

843


What are the differences between string, stringbuffer and stringbuilder?

759


What is the difference between break and continue statements?

816


What are the properties of thread?

705


Can we write any code after throw statement?

835


what is object slice?

1780


What is the difference between processes and threads?

787


What is percentage in java?

786


What is a generic data type?

762


What are new features introduced with java 8 ?

753


Which sorting algorithm is best in java?

765


What is an image buffer?

740


Can we override private constructor in java?

735


What is difference between filereader and bufferedreader?

747