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?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Umesh K
  • 13,436
  • 25
  • 87
  • 129

1 Answers1

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.
}
christopher
  • 26,815
  • 5
  • 55
  • 89