2

What's the easiest way to change ArrayList<String[]> to String[][]/Object[][] table?

I tried to use size() method, but this type of list doesn't have simple method get().

Thanks for help.

_rowTable[j][0] = new String[_listSelect.size()][columnCount];

for(int j=0; j < _listSelect.size(); j++)
 //   for(int k=0; k < columnCount; k++)
        _rowTable[j][0] = _listSelect.get(0);

How to use second loop inside properly?

2 Answers 2

12

I would use List.toArray(T[])

List<String[]> listOfStringArray = ...
String[][] arrayOfStringArray = listOfStringArray.toArray(
                                        new String[listOfStringArray.size()][]);
Sign up to request clarification or add additional context in comments.

1 Comment

Cast to String[][] is redundant.
1

try this

List<String[]> list = new ArrayList<>();
...
Object[][] objectArray = list.toArray(new Object[list.size()][]);
String[][] stringArray = list.toArray(new String[list.size()][]);

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.