Results 1 to 2 of 2
  1. #1
    elm101 is offline Member
    Join Date
    May 2011
    Posts
    5
    Rep Power
    0

    Default variable declaration

    so i have a string and i want to name a different variable with
    that string
    ex:
    Java Code:
    String str = "name";
    int *;// the star would be name, but i want to do be able to do this if i don't know what the string variables value is
    any thoughts?

  2. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    5

    Default Re: variable declaration

    Identifiers don't exist at runtime, so you can't manipulate them with your code. Try using a HashMap instead.

    Java Code:
    HashMap<String, Integer> hm = new HashMap<String, Integer>();
    hm.put("foo", 7);
    hm.put("bar", -8886);
    System.out.println(hm.get("foo")); // prints 7

Similar Threads

  1. array declaration
    By maya700 in forum New To Java
    Replies: 1
    Last Post: 03-07-2011, 05:33 PM
  2. Replies: 4
    Last Post: 05-18-2009, 03:23 PM
  3. Declaration
    By asifahmed in forum New To Java
    Replies: 1
    Last Post: 04-05-2008, 06:38 AM
  4. multiple declaration of a variable
    By eva in forum New To Java
    Replies: 2
    Last Post: 01-28-2008, 10:17 AM
  5. JSP Declaration Directive
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-10-2007, 06:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •