Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using string value as a variable name

 
Prakash Balasubramani
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

How to convert a string into variable name. For example i have a variable named "myname" with value "sachin" in it i.e myname="sachin".

Then in an string i have a name of the variable. using this strings value how to print the name sachin. i.e if myString = "myname" how to print "sachin" using this string variable?

eg code:

myname = "sachin";

String myString = "myname";

i want out.println(myString) to print "sachin".

Thanks in advance for ur help.

Bye,

B.Prakash.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Print where?
stdout?
The webpage?
 
Prakash Balasubramani
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to print it in WebPage
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i hope it helps

StringBuffer myname = new StringBuffer();
name.append("sachin");
StringBuffer mystring = myname;
out.println(ename.toString());
 
g forte
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String myname = "sachin";

String myString = myname; // get rid of the quotes so that you set myString equal to the value of myname, instead of setting myString equal to myname.

out.println(myString);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic