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 839027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:24:00+00:00 2026-05-15T05:24:00+00:00

I have a set of data which needs to be imported from a excel

  • 0

I have a set of data which needs to be imported from a excel sheet, lets take the simplest example. Note: the data might eventually support uploading any locale.

e.g. assuming one of the fields denoting a user is gender mapped to an enumeration and stored in the database as 0 for male and 1 for female. 0 and 1 being short values.

If I have to import the values I cannot expect the user to punch in numbers (since they are not intuitive and is cumbersome when the enumerations are bigger), what would be the correct way to map to enumerations.

Should we ask them to provide a string value in these cases (e.g. male or female) and provide the transformation to a enum in our code by wring a method public static Gender Gender.fromString(String value)

  • 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-05-15T05:24:01+00:00Added an answer on May 15, 2026 at 5:24 am

    You don’t need to write a fromString; enum types already have a static valueOf(String):

    public class EnumValueOf {
        enum Gender {
            MALE, FEMALE;
        }
        public static void main(String[] args) {
            Gender g = Gender.valueOf("MALE");
            System.out.println(g);
            // prints "MALE"
            System.out.println(g == Gender.MALE);
            // prints "true"
        }
    }
    

    The specification

    It’s somewhat hidden, but this is specified in JLS.

    JLS 8.9 Enums

    In addition, if E is the name of an enum type, then that type has the following implicitly declared static methods:

    /**
    
    * Returns an array containing the constants of this enum 
    * type, in the order they're declared.  This method may be
    * used to iterate over the constants as follows:
    *
    *    for(E c : E.values())
    *        System.out.println(c);
    *
    * @return an array containing the constants of this enum 
    * type, in the order they're declared
    */
    public static E[] values();
    
    /**
    * Returns the enum constant of this type with the specified
    * name.
    * The string must match exactly an identifier used to declare
    * an enum constant in this type.  (Extraneous whitespace 
    * characters are not permitted.)
    * 
    * @return the enum constant with the specified name
    * @throws IllegalArgumentException if this enum type has no
    * constant with the specified name
    */
    public static E valueOf(String name);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very large set of data (~3 million records) which needs to
I have a new rails app which needs to access data from a legacy
I have a JavaScript-based timeline which needs to use data from an SQL server.
I have a large set of data which I access via a generator/iterator. While
I'm pretty new to Entity Frameworks. I have a set of Static Data which
I have a data set which consists of an ID and a matrix (n
I have a set of data points in 3D space which apparently all fall
I have the swiss data set provided by R, which has the following form:
I have a set of controls bound to data, on which I would like
I have a mysql table field set as time type which stores data in

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.