Question :Strings are immutable, How are we able to perform concatination on
String object? (CoreJava)
Answer :Yes. Strings are immutable. Thats why while concatenating, it always
returns a new string object.
If we take this example :
String s1 = "psn";
s1 = s1.concat("prasad"); // Here you are reassigning the new object to
the older reference s1
System.out.println(s1);
String s1 = "psn";
String s2 = s1.concat("prasad");
System.out.println(s1); // will remain same . no change. it prints "psn"
only
System.out.println(s2); // as you have assigned the newly created object
to s2
www.interviewhelper.org is a hope for all the Job seekers. Users can find unlimited here. These range from technical to HR, from functional to behavioral. www.interviewhelper.org contains in the fields like Ajax,VB,Networking,Sharepoint,JEE,Perl,Javascript,Bioinformatics,Classic ASP,Unix,Linux,Accounting,Oracle DBA,Microprocessor,Bluetooth,jms,jme,.net framework,ABAP,ASP,ASP.net,Basic .net Framework,Interview Questions,C language,C++,database,Oracle,Java,PHP,LAMP,SAP etc.
Thursday, March 12, 2009
Strings are immutable, How are we able to perform concatination on
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment