Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

toUpperCase() and concat()

 
R K Singh
Ranch Hand
Posts: 5384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what does this mean:
The toUpperCase() and concat() methids modifies their associated String object.
This stmt is at
http://www.jaworski.com/java/certification/
while explaning the ans for a que.
I looked at source code but there also both methods cretae new String and return .
so what does it mean..
I found this in archive:
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=008253
hi shiva .. look I searched
it takes time but .. OK. I will do it for you ..
but here they say it is typo..
typo at two places for same reason..
I think jaworski need to updae his site OR knowledge
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The discussion on the link you provided gives the answer. Basically, String objects are immutable, so no methods of the String class can modify the String object on which they are invoked. If the result of the method leaves the String unchanged (for instance invoking toLowerCase on a String containing ONLY lowercase characters) then the same String object is returned otherwise a completely new String object is returned.
For instance:
String t1 = "test";
String t2 = t1.toLowercase(); // t1 and t2 reference the same object
String t3 = t1.toUpperCase(); t3 refers to a completely new String object
HIH
[ January 16, 2002: Message edited by: Valentin Crettaz ]
 
R K Singh
Ranch Hand
Posts: 5384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic