Hi there,

I'm having a rather bad morning today and my brain is being stupid. I have an ArrayList containing String Arrays. How do I convert my ArrayList to a 2D Array?

What I have:

ArrayList<String[]> transactionList = new ArrayList<String[]>();
String[] resultSetRow = {"String1","String2","String3","String4","String5"};

int resultsSetRowSize = resultSetRow.length;
for(int n = 0; n < resultsSetRowSize; n++){
   transactionList.add(resultSetRow[n]);
}

//How to convert transactionList to Array[][] ?

Thanks in advance!

Nevermind, I figured it out.. Thanks anyways

String[][] lstTransactions = (String[][])transactionList.toArray();

Yeap, you can do that. Also you may want to have look on Google Guava library class Lists

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.