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

  • Home
  • SEARCH
  • 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 9104021
In Process

The Archive Base Latest Questions

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

Say I need a data structure in Java involving one set of categories, each

  • 0

Say I need a data structure in Java involving one set of categories, each with one set of subcategories. For example, let’s say the main category is ‘brand’ (like, of a product) and the subcategory is ‘product’. I want to be able to map the combination of brand+product to a piece of data e.g. a price.

I’d like to use an enum type for both ‘brand’ and ‘product’ if they were on their own, because

  • Brand+product has only a small, single piece of data tied to it (the price)

  • I need to refer to them many times throughout a reasonably large program, so the chance that I’ll mistype any string literal keys I assign to them is basically one.

However, the number of brands/products is too large to have a single enum for each brand/product combination (around twenty brands each with ten products and a good chance of adding more later). I’d like to be able to use the structure like this:

    getPrice(APPLE.IPOD)

    getPrice(APPLE.MACBOOK)

    getPrice(HERSHEYS.PEANUT_BUTTER_CUPS)

Should I use some sort of nested enum? If so, how would that be implemented?


Bonus information: I’ve spent a bit of time googling ‘java nested enum’ but haven’t come up with anything. The problem with structures like the first one in the ticked answer here or thelosts’s answer here is that I have too many categories all exhibiting the same behavior to write out very similar enum definitions so many times.

  • 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-17T01:45:58+00:00Added an answer on June 17, 2026 at 1:45 am

    I wouldn’t use an enum for this.

    I would suggest you load this information from a file or database. Java is not a good place for storing large amounts of data.

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

Sidebar

Related Questions

Let's say I want to create a complex data structure consisting of multiple mutually
Let's say I'm writing a little library in C -- some data structure, say.
I need to import data from *.dmp file say mydump.dmp. What I'm doing is:
I need to manipulate a large amount of numerical/textual data, say total of 10
Let's say I need to upload files to a server programmatically using uploading a
Let's say I need to take names of movies the person likes. I don't
Let's say i need to find all .bar elements inside an element that's assigned
Let's say I need to use Python and C++. I can call Python function
Let's say I need to develop a plugin for a given technology not supported
Say I have a Group data structure which contains a list of Element objects,

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.