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
List the interfaces which extends collection interface?
What is a variable in java?
What are the characteristics of Final,Finally and Finalize keywords.
What is array initialization in java?
What is meant by JVM? Is JVM platform independent or not?
What do bitwise operators do?
What is data type example?
What are the different types of sorting in java?
How we can generate random numbers in java?
What is the program development process?
What is the maximum size of list in java?
List types of storage classes in java?
What is complexity in java?
Difference between error and exception
What comes to mind when someone mentions a shallow copy in java?