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

The Archive Base Latest Questions

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

There is a list of objects I need to add to a grid without

  • 0

There is a list of objects I need to add to a grid without receiving an IndexOutOfBoundsException. Each object has two numbers associated with it which corresponds to it’s index and column position in a grid. There can be 3 columns and unlimited rows. I need to call add() method for this grid but only in the correct order, so :

(0,0),(0,1),(0,2),(1,0)…

The grid would therefore look like this:

  0 1 2
0 x x x
1 x x x
2 x x x
3 x x x

I must also take into account the chance that no object exists for a certain position. For example:

A) x x x  B) x   x   C) x x x
   x x x     x   x        x x
   x   x         x        x
   x   x         x        x
   x   x

Can this be done? I’m not sure where to start.

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

    Maybe you should think about another datastructure that stores objects by (row,column). It’s interface would look like

    public interface GridModel {
      void set(int row, int column, Object o);
      Object get(int row, int column)
    }
    

    And than you can use a list of lists to store the data. List<List<Object>> or, as Mark Peters suggests, a sparse matrix

    If working with the cell values is important, add a cell iterator method. A simple implementation would look like:

    public Iterable<Object> cellIterator() {
        final List<Object> items = new java.util.ArrayList<Object>();
        for(final List<Object> row : cells) {
            for(final Object cell: row) {
                items.add(cell);
            }
        }
        return items;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to compare two lists where each list contains about 60,000 objects. what
I have a 2D space with objects, each object has coordinate vector and an
There is a classItem and it has some associated classes called Vehicle,Vmodel,Category,ItemName,Brand,SizeModel.Those each class
Is there a complete list of the objects you can tap into with <%$
Is there a list somewhere on common Attributes which are used in objects like
Is there a way to collect (e.g. in a List) multiple 'generic' objects that
I have a class Player that contains a list of Accessory objects. There are
I have a List object being accessed by multiple threads. There is mostly one
Is there a way to convert a List(of Object) to a List(of String) in
Is there any way to determine if an object is a generic list? I'm

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.