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

What is the difference between jvm and jre? What is an interface?

555


Explain aggregation in java?

549


Which access specifier can be used with class ?

539


Where can I find jdk in my computer?

470


Can you call a method in a method?

537






What is flag in java?

539


Can private method static?

475


What data structures are used to perform recursion?

608


What is use of super keyword in java?

606


Explain implementation and how is it different from conversion?

595


Which is faster set or list in java?

538


Can inner class be public in java?

558


What are the advantages of user defined functions?

562


Write a program to reverse array in place?

598


How is java hashmap implemented?

559