Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


When you say String is immutable, what do you mean by that?
Say I have String s = "Ness"
s= s+"Technologies";
What will happen? If the value gets appended, then what is
the meaning of immutable here?

Answers were Sorted based on User's Feedback



When you say String is immutable, what do you mean by that? Say I have String s = "Ness" ..

Answer / haribabu

Once you have assigned a value to a "String Object" (i am
saying an "object" not the "object reference")that value
can never change. This is immutability.

by defining "s = s+Technologies" we are pointing the
REFERENCE to newly created "string object" with the
modified string. So the previous string object is
considered to be lost.

This concept has explained very well in String, I/Os
chapter of Kethy Siera, SCJP 5.

All the best

Is This Answer Correct ?    26 Yes 0 No

When you say String is immutable, what do you mean by that? Say I have String s = "Ness" ..

Answer / harmetkrishanan

every time a new String object gets created in this case.

Is This Answer Correct ?    24 Yes 5 No

When you say String is immutable, what do you mean by that? Say I have String s = "Ness" ..

Answer / bln

Every time a new String objects gets created in this case,
but if assigned value is not same. If assigned, value is
same, then it points to same memory location, even if it is
another variable. For ex;
String s="Test";
String s2="Test";

Now s, s2 points to the same memory location.

Is This Answer Correct ?    20 Yes 2 No

When you say String is immutable, what do you mean by that? Say I have String s = "Ness" ..

Answer / r.jainrocks@gmail.com

When concatenation operator "+"
used with string

it always creates a new String object,
in String pool area.

Is This Answer Correct ?    11 Yes 0 No

When you say String is immutable, what do you mean by that? Say I have String s = "Ness" ..

Answer / anjani kumar jha


Now u add s= s+"Technologies";
so it will NessTechnologies because you append. and assign
new varible,means that new addition is assigned to s

take one example for more clarity

String x = "Java";
x.concat(" Rules!");
System.out.println(x);

output is x=java
because string is immutable.............think hard on it


Consider the following another example---------and think
about that

public class NewClass {

public static void main(String as[])
{
String s="abc";
String s1=s+"cde";
System.out.println(s);
System.out.println(s1);


String x = "Java";
x.concat(" Rules!");
System.out.println(x);
}

}
output is
s=abc;
s1=abcde
x=java

since u have added cde in s but still from the output it is
abc...............means string is immutable,

For more contact me
Anjani Kumar jha
09623154095
CDAC,PUNE

Is This Answer Correct ?    6 Yes 4 No

Post New Answer

More Core Java Interview Questions

3) Suppose you are a very rich person, having 50 rooms and you have lost the key for one of the room's. How effectively you can find this key? (Qs2 and Qs3 are related)

3 Answers   RBS,


What is a void method?

0 Answers  


How to split arraylist elements in java?

0 Answers  


I want to store more than 10 objects in a remote server? Which methodology will follow?

0 Answers  


What is the need of "creating and throwing an UserdefinedException" when the "Exception" class is already available?

4 Answers  


How to declare unique ArrayList ?

6 Answers   RMSI,


Which non-unicode letter characters may be used as the first character of an identifier?

0 Answers  


How does linkedhashmap work in java?

0 Answers  


Is it possible to cast an int value into a byte variable? What would happen if the value of int is larger than byte?

0 Answers  


What is the difference between length and size in java?

0 Answers  


How do you escape in java?

0 Answers  


What is the gregoriancalendar class in java programming?

0 Answers  


Categories