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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:38:23+00:00 2026-05-26T07:38:23+00:00

Lets say we have a class called CompHash with 30 different variables as follows:

  • 0

Lets say we have a class called CompHash with 30 different variables as follows:

   public class CompHash{
      private String abc1;
      private int sdf2;
             :
             :
      private float sgh30;
   }

and a similar class:

     public class CompHash{
         private HashMap diffVariables;
     }

In a situation where the number of variables that I will be needing varies from 1 to 30, which of the two would be better?

  • 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-26T07:38:24+00:00Added an answer on May 26, 2026 at 7:38 am

    In general you should always prefer strongly typed CompHash (the first one). Not only it is safer, but it will also be significantly faster.

    If you have a requirement to store arbitrary number of variables, HashMap might be a good choice. But remember you are sacrificing type-safety without much gain – HashMap will probably still occupy more memory as opposed to a single object with lots of nulls.

    The only valid usage of HashMap is when you need to store arbitrary pairs (it is not clear whether variables/key names are constant in your case) of key -> value. But in this scenario I would recommend wrapping primitives with a class hierarchy having common ancestor and using Visitor pattern to avoid dangarous down-casts and ugly instanceof‘s.

    BTW what problem are you actually solving? The data structure you need seems a bit exotic…

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

Sidebar

Related Questions

Let's say I have a class called AppConfig: public static class AppConfig { private
Lets say I have: class Zebra{ public static function action(){ print 'I was called
Lets say I have this class in foobar-shared.lib: class FooBar { std::string m_helloWorld; }
Lets say I have a simple Enum called Animal defined as: public enum Animal
Lets say I have the following code: public class Base { // Some stuff
Lets say I have a class like this in Java: public class Function {
Lets say I have a class called PageBuilder which I instantiate, send parameters to
So lets say I have a class called Post that contains an IList I
Lets say i have a page called https://url.com/test and https://url.com/test2 class Test extends Application
Here's what I'm thinking. So lets say I have a class called intro 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.