• Post Reply Bookmark Topic Watch Topic
  • New Topic

toUpperCase() method of String  RSS feed

 
kiran nyala
Ranch Hand
Posts: 55
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,




output:

LOWER
lower
lowerCASE


Why such behavior shown by String.As String is immutable , does s1.toupperCase() creates new string object ??
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kiran nyala wrote:does s1.toupperCase() creates new string object ??

Yes, that's right.
 
kiran nyala
Ranch Hand
Posts: 55
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, that means the original string s1 will not change its state, where as s1.toUpperCase() will create new string object with no reference in stack right ?.

If so, does all string functions like ( concat(), toLoweCase(), trim() ) will act same ?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kiran nyala wrote:If so, does all string functions like ( concat(), toLoweCase(), trim() ) will act same ?

Yup.

And BTW, don't worry about things like stacks and pools and such like. Just take it as read that any time you do something with a String, you will get another String.

Winston
 
kiran nyala
Ranch Hand
Posts: 55
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your assistance Mr.Winston..!
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kiran nyala wrote:thank you for your assistance Mr.Winston..!

You're most welcome.

And don't forget that when I say "do something with a String", that also includes the '+' operator.

Winston
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

that means the original string s1 will not change its state


Java Strings are known to be immutable.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!