• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using string value as a variable name

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Print where?
stdout?
The webpage?
 
Prakash Balasubramani
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to print it in WebPage
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i hope it helps

StringBuffer myname = new StringBuffer();
name.append("sachin");
StringBuffer mystring = myname;
out.println(ename.toString());
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic