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?
Answer Posted / 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 View All Answers
What is the difference between && and & in java?
What is difference between local variable and global variable?
Can we override protected method in java?
Explain about features of local inner class?
What does yield method of the thread class do?
What are static initalizers in java ?
How do you use nextline in java?
I want my class to be developed in such a way that no other class (even derived class) can create its objects. How can I do so?
Why is it called buffering?
Is simpledateformat safe to use in the multithreaded program?
Define array. Tell me about 2-D array.
What are the difference between string, string builder, and string buffer in java?
What is a qms manual?
Which package is used for pattern matching with regular expressions?
Can we extend singleton class in java?