ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories >> Software >> Java-Related >> Java-J2EE >> Core-Java
 
 
 
Question
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?
 Question Submitted By :: Maria
I also faced this Question!!     Rank Answer Posted By  
 
Answer
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
 
0
Anjani Kumar Jha
 
View All Answers
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com