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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:24:42+00:00 2026-06-13T12:24:42+00:00

Possible Duplicate: Table like java data structure I am looking for a Table-like data

  • 0

Possible Duplicate:
Table like java data structure

I am looking for a Table-like data structure for Java. So far I have not been able to find one and it is really frustrating as I know for sure there must be one. Please note this has nothing to do with a graphical representation of the table, just the logical model.

The idea is simple, you have a table like:

+-------+-----+-----------+
| Name  | Age | city      |
+-------+-----+-----------+
| Steve | 21  | London    |
| John  | 40  | Amsterdam | 
+-------+-----+-----------+

Now I need to iterate over the different rows and retrieve the values based on the column name. It has to be flexible so I don’t know the column names up front (so a list of beans is not an option). The best structure I could find that has this ability is a java.sql.ResultSet, but I don’t feel comfortable using that in a non SQL related context. I also don’t want a list of HashMaps as that would mean storing the keys for every row, which would be very inefficient.

It seems like such a basic structure yet I cannot find anything about it due to the overwhelming amount of GUI related posts when searching for table like structures in Java.

EDIT

For a concrete example of what I need, the following piece of code:

TableStructure table = getTable(); // Gets my desired table with its filling

while (table.next()){
    System.out.println("Name: " +  table.get("Name"));
    System.out.println("Age: " + table.get("Age"));
    System.out.println("City: " + table.get("City"));
    System.out.println("NonExistent: " + table.get("NonExistent"));
}

Should produce the following output:

Name: Steve
Age: 21
City: London
NonExistent: null
Name: John
Age: 40
City: Amsterdam
NonExistent: null
  • 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-13T12:24:43+00:00Added an answer on June 13, 2026 at 12:24 pm

    A ResultSet is a list (or a set, dependant on necessity of ordering and multiplicity of elements) of tuples, so a really generic answer would be

    class TableStructure<Tuple>
    {
        List<Tuple> tuples;
        Iterator iterator;
    
        public Tuple next() 
        {
            if ( iterator == null ) { iterator = tuples.iterator(); /* NPE prone */ }
            return iterator.next()
        }
    }
    

    (or better, have TableStructure extend List and use the iterator directly)

    where

    class Tuple { Map<String,Object> attributes; }
    

    This construct allows for different row sizes within your table, which in a DB setting violates the first (or the second?) normal form principle.

    Hope that helps a bit.

    Cheers,

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

Sidebar

Related Questions

Possible Duplicate: Concatenate row values T-SQL I have a table like this: ref_num name
Possible Duplicate: Fetch data in database table insert it if not exist else return
Possible Duplicate: SQL query to find Missing sequence numbers I have a table which
Possible Duplicate: one variable row inside another variable row I have script something like
Possible Duplicate: Function to Calculate Median in Sql Server I have a table like
Possible Duplicate: Find the number of columns in a table I would like to
Possible Duplicate: SQL Server dynamic PIVOT query? I have temporary table with following structure:
Possible Duplicate: SQL: Find the max record per group I have a table with
Possible Duplicate: Core Data vs SQLite 3 I have been using SQLite for saving
Possible Duplicate: Printing Table's structure/schema oracle has 'DESCRIBE' to get all the details of

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.