G
George
Dear All,
My understanding is that String objects are immutable, thus you can not
change them but any changes will be saved in a different object of the
same class.
I have written the following simple programme, that converts the string
Hellow World to upper case and prints it.
public class Test{
public static void main(String[] args){
String str1=new String("Hello World");
str1 = str1.toUpperCase();
System.out.println(str1);
}
}
If str1 is immutable as a String object, then how can we save the results
of the conversion back to the same object? Should that not be a different
one? What am I missing here?
Thanks,
George
Computers are useless. They can only give you answers.
Pablo Picasso (1881-1973)
My understanding is that String objects are immutable, thus you can not
change them but any changes will be saved in a different object of the
same class.
I have written the following simple programme, that converts the string
Hellow World to upper case and prints it.
public class Test{
public static void main(String[] args){
String str1=new String("Hello World");
str1 = str1.toUpperCase();
System.out.println(str1);
}
}
If str1 is immutable as a String object, then how can we save the results
of the conversion back to the same object? Should that not be a different
one? What am I missing here?
Thanks,
George
Computers are useless. They can only give you answers.
Pablo Picasso (1881-1973)