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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:54:33+00:00 2026-06-18T15:54:33+00:00

I have an arraylist and each element of the arrayList contains a small arrayList

  • 0

I have an arraylist and each element of the arrayList contains a small arrayList of data.

I need to create a table from this data. What would you recommend being the best route to take with solving this?

Thanks in advance for any help

  • 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-18T15:54:34+00:00Added an answer on June 18, 2026 at 3:54 pm

    To display a GUI table of a List of lists, I would create a class that implements the ‘TableModel’ interface, and has a constructor that takes in your ‘List>’

    public class ListTableModel <T> implements TableModel {
    
        private List<List<T>> source;
    
        public ListTableModel(List<List<T>> source) {
    
            this.source = source;
    
        }
    
    
        //Override 'getRowCount' 
        //The row count would be calculated as the size of the outer list.
        @Override
        public int getRowCount() {
            return source.size();
        }
    
        //Override 'getColumnCount'
        //The column count would be calculated as the max size of the inner lists
        @Override
        public int getColumnCount() {
            int max = 0;
            for(List<T> row : source) {
                max = Math.max(max, row.size());
            }
            return max;
        }
    
        //Override 'getColumnName'
        //Lets go ahead and just give a unique name to each column based on the index.
        //This could be populated from an input taken by the constructor, but we
        //won't worry about that now.
        @Override
        public String getColumnName(int columnIndex) {
            return "Column " + columnIndex;
        }
    
        //Override 'getColumnClass'
        //The class would technically be the generic type 'T', so to get this we 
        //will simply just get the calss of the first element.
        @Override
        public Class<?> getColumnClass(int columnIndex) {
            return source.get(0).get(0).getClass();
        }
    
    
        //Override 'isCellEditable'
        //I'm going to assume we don't want cell to be editable.
        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
        }
    
        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            List<T> row = source.get(rowIndex);
            if(columnIndex >= row.size())
                return null;
            else 
                return row.get(columnIndex);
        }
    
        @Override
        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
            //required but we will assume that you cannot change the source list
            //if we needed to, it wouldn't be too difficult to implement.
        }
    
        @Override
        public void addTableModelListener(TableModelListener l) {
            //required but not used (will only be used if the source could change)
        }
    
        @Override
        public void removeTableModelListener(TableModelListener l) {
            //required but not used (will only be used if the source could change)
        }
    
    }
    

    you would use this model with your list like so:

    List<List<String>> myList = new ArrayList();
    
    //Populate 'myList'...
    
    JTable table = new JTable();
    
    //Add table to view...
    
    table.setModel(new ListTableModel(myList));
    

    EDIT I can show you how to implement TableModel if you would like.

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

Sidebar

Related Questions

I have string arraylist [rose,flower,banana,parrot,rose,bird,flower,rose,banana,bird] From this array I want last index of each
I have an Arraylist of HashMap . Each HashMap element contains two columns: column
I create a custom table, not extends from JTable, and i have a huge
I have an ArrayList . Each element is a HashMap lookup for my values.
I have a List of Locations ArrayList<Location> locationList; Each Location contains informations like name,
I have a list of linkedlist. List<LinkedList<File1>> lists = Collections.synchronizedList(new ArrayList<LinkedList<File1>>()); each linkedlist contains
I have an ArrayList of type modules, each module has an arraylist of Assignments.
I have arraylist myorderdata . I want to retrieve this arraylist to one String
I have an ArrayList of HashMap like this: ArrayList<HashMap<String, String>> playListSongs = new ArrayList<HashMap<String,
I have an ArrayList of Routine objects and I must use this method to

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.