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 are the advantages of user defined functions?

753


What is r * in math?

732


Explain about assignment statement?

805


What is the new line character?

835


What is binary tree in java?

766


What are the four integer types supported by java?

789


Can we sort array in java?

719


How do you know if a value is nan?

802


What means public static?

786


What is the advantage of OOP in java?

884


Define an applet in java?

839


How does multithreading take place on a computer with a single cpu in java programming?

747


Can we serialize singleton class?

772


What is the lifetime and scope of a variable?

756


What is ctrl m character?

741