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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:51:26+00:00 2026-05-26T02:51:26+00:00

I’m still not very much used to Java. I have a class which should

  • 0

I’m still not very much used to Java. I have a class which should contain a List. One could imagine this list representing a row in a table (column name, value of certain type):

Name - "Oskar",
Age - 28,
weight - 75.5,
weightUnit - "kilogram",
...

As the content of the list should be flexible, I cannot use class member variables.
Basically, the programmer is blind to the content. But then, at some point – I have to extract all entries with double values. How would you implement something like this?

  • 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-26T02:51:27+00:00Added an answer on May 26, 2026 at 2:51 am

    You could create a class that represents a column, and then represent a row as a list of columns:

    public class Column {
        private String name;
        private Class clazz;
        private Object value;
    
        public Column(String name, Class clazz, Object value) {
            this.name = name;
            this.clazz = clazz;
            this.value = value;
        }
    
        // ...
    }
    

    Your data would then be:

    List<Column> row = new ArrayList<Column>();
    row.add(new Column("Name", String.class, "Oskar"));
    row.add(new Column("Age", Integer.class, 28));
    row.add(new Column("weight", Double.class, 75.5));
    row.add(new Column("weightUnit", String.class, "kilogram"));
    

    However, it looks like you’re trying to create a database, so you might want to have a Table class which would have a List<ColumnDescriptor>, where ColumnDescriptor would be like the above Column class, only without the value — just the name and type. And then perhaps have a TableRow class that would have a List<Object> of all the values. When you add a row to a table, you would want to validate that the values are compatible with the types of the columns of that table.

    You might want to look at the way JDBC is designed for inspiration. Supporting all the needed generality, functionality, and making it all type-safe is a lot of work. Unless you really need this for an ORM tool, custom reporting solution, or an actual database, you might want to rethink the design and ask if this much generality is necessary. (“Do the simplest thing that could possibly work.”)

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.