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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:14:23+00:00 2026-05-27T10:14:23+00:00

Im working on java, I have created an enum as follows: public enum myEnum

  • 0

Im working on java, I have created an enum as follows:

public enum myEnum
{
    india,
    russian,
    england,
    north America
}

Above example gives errors while using space in the name of element (i.e. north America).
Any suggestions how to resolve above issue?

  • 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-27T10:14:24+00:00Added an answer on May 27, 2026 at 10:14 am

    You can’t put a space in the middle of an identifier.

    Doing so ends that identifier and the parser assumes whatever comes next is a valid token in that statement’s context. There are few (if any) places that would be legal.

    Conventional Java value names would be:

    INDIA,         // Or India,
    RUSSIA,        //    Russia,
    NORTH_AMERICA; //    NorthAmerica;
    

    An enum can have associated properties, like human-readable names, e.g.,

    public enum CountryAndOneContinent {
        INDIA("India"),
        RUSSIA("Russia"),
        NORTH_AMERICA("North America");
    
        private String displayName;
    
        CountryAndOneContinent(String displayName) {
            this.displayName = displayName;
        }
    
        public String displayName() { return displayName; }
    
        // Optionally and/or additionally, toString.
        @Override public String toString() { return displayName; }
    }
    

    I’m ambivalent about using toString to provide presentation-layer representations.

    I prefer methods communicate their purpose explicitly–it’s more expressive and obvious.

    toString is pretty generic, and allows only a single representation. Multiple output formats may be required depending on context, parameters, etc. which toString doesn’t allow.

    Advantages of toString include using default string operations on the object, and in this case, using valueOf to directly translate from the human-readable version to the enum value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a couple of java working sets for a project in my
I'm working on a Java project where I have created a class that looks
I am working with a java Twitter app (using Twitter4J api). I have created
Working on my assignment for Java and I have created a class called Triangle.
I am working with Java. I have created one text file. In that text
I have been working with Java a couple of years, but up until recently
I have been working in Java/J2ee projects, in which I follow the Maven structure.
I'm working with java, trying to use the AudioFormat Class. I have the following
I have been working on a Java project for a class for a while
I am working on a Java project and need to have a keypress simulate

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.