0

I would like to convert ArrayList into 2D array of Objects. List is something like

[[AD,ADCB, N], [AFC, Fund, Y], [IO, dfdfdfd, N]]

I would like to convert this List into array of objects and I would like to modify Y, N field into Boolean Values someting like

Object[] rowdata = {
    {AD, ADCB, Boolean.FALSE}, 
    {AFC, Fund, Boolean.TRUE}, 
    {IO, dffdfdf, Boolean.FALSE}}

after that I can stuff into JTable model and those boolean values will be visible as JCheckboxes.

What should be the best way to convert this list into 2D array of objects so that I can pass into JTable TableModel?

3

1 Answer 1

1

In your example, you show that there are three members of each object that you want to store. So, if N is the number of items in your arraylist, you need a multidimensional array of N * 3. ie:

Object[][] table = new Object[list.size()][3];

Then you're going to use a for loop, to cycle through each object in the list:

for(int x = 0; x < list.size(); x++)
{
     Object currentObject = list.get(x);
     table[x][0] = currentObject.getValue();
     // Load the first value.
     ...
     table[x][2] = currentObject.getYorN().equalsIgnoreCase("Y")? true:false;
     // Embed a selection statement to decide if to store true or false.
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.