File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

change given string literal value to another value

 
mikali singh
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to change the given string literal value to another value using only one variable and without using string buffer and builder. for example-
String s= "hello dudes" to String s= "hello java DUDES beignners" using only one variable s.
 
Greg Charles
Sheriff
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

Strings can't be changed. That's a good concept to drill into yourself early and often. However, you can assign a different String value to the variable s, which may be what you meant. I'm not clear on your assignment though. Are you supposed to transform the first String "hello dudes" to the second based on some rules? Keep in mind we won't do your homework for you, but if you're clearer about the problem, we can point you in the right direction.
 
Ishan Pandya
Ranch Hand
Posts: 225
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mikali singh wrote:how to change the given string literal value to another value using only one variable and without using string buffer and builder. for example-
String s= "hello dudes" to String s= "hello java DUDES beignners" using only one variable s.


Remove the second declaration of the "String s". you can directly assign a new value to variable "s" which was already defined (which will lose its previous reference to "hello dudes" from the constant pool).
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12021
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is wrong with



Technically, neither string has changed. You are now simply pointing the reference variable s to a new, different string.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic