Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Enum with strings

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Enum with strings

    I have a quick question which shouldn't be too hard to answer.

    So in my main function I take a user input for which enum element to use.

    So I have String type = scanner.next();

    User input: grannysmith

    I also have an enum called apples.

    What I want is to do is create and use apples.grannysmith, but I do not know how to do this.

    Do I do one of these:
    apples.type;
    new apples.type();

    Or something else similar??

    Thanks for the help


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Enum with strings

    I don't know of any way to use data read into a program as a variable name.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. enum
    By anis.laghaei in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 23rd, 2012, 03:19 PM
  2. [SOLVED] Alternative to Enum
    By Doctor X in forum Java Theory & Questions
    Replies: 2
    Last Post: October 6th, 2012, 03:49 PM
  3. [SOLVED] Enum types, how does he know %s value?
    By beer-in-box in forum Java Theory & Questions
    Replies: 11
    Last Post: September 17th, 2011, 12:47 PM
  4. Declaring enum problem
    By kumalh in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 5th, 2011, 06:30 AM
  5. [SOLVED] Enum problem
    By pajfilms in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 21st, 2011, 07:26 AM