Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9165631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:57:05+00:00 2026-06-17T14:57:05+00:00

How can I gen an actual value from this enum with switch statement? public

  • 0

How can I gen an actual value from this enum with switch statement?

public enum Gender {
    Unknown(0),
    Male(1),
    Female(2);

    private static final SparseArray<Gender> lookupTable = new SparseArray<Gender>();
    static {
        for (final Gender gender : EnumSet.allOf(Gender.class)) {
            lookupTable.put(gender.intValue, gender);
        }
    }

    private final int intValue;

    public static Gender getByIntValue(int val) {
        return lookupTable.get(val);
    }

    private Gender(int intValue) {
        this.intValue = intValue;
    }

    public int getIntValue() {
        return intValue;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:57:06+00:00Added an answer on June 17, 2026 at 2:57 pm

    It is not entirely clear hat you mean with ‘actual value from this enum with switch statement‘. So here are the things to do with this enum:

    You can use the enum in a switch-statement as follows:

    Gender g = ...
    switch(g) {
       case Male:
         // Do something for the males
         break;
       case Female:
         // Do something for the females
         break;
       case Unknown:
         // Argh... What to do?!
         break;
    }
    

    If you want to grabintValue of g, you can use:

    int value = g.getIntValue();
    

    If you want to grab a Gender value from an int you can use:

    Gender g = Gender.getByIntValue(1);
    

    If you want to grab a Gender value from a String you can use:

    Gender g = Enum.valueOf(Gender, "Male");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use function cartesian from List::Gen . This function requires LIST as
Can someone please tell me where these extra characters are coming from? This is
How can one loop through a generator? I thought about this way: gen =
How can I make this script grab the nmv-fas from the link name and
Can anyone let me know how can we change the value of kendo combobox
Can I change the field public virtual ClassOne ClassOne { get; set; } to
I know this question has been asked/answered but I can't find it for the
I would like to create an application from a database schema using seam-gen; unfortunately
I am new to Haskell and I wonder how/if I can make this code
On my first-gen Macbook Pro, with OS X 10.6.1, I can launch gnuplot and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.