Skip to content

Instantly share code, notes, and snippets.

@ekosuhariyadi
Last active January 30, 2017 13:54
Show Gist options
  • Save ekosuhariyadi/d4f592f92c96c3f2ce75fc58f848bf7e to your computer and use it in GitHub Desktop.
Save ekosuhariyadi/d4f592f92c96c3f2ce75fc58f848bf7e to your computer and use it in GitHub Desktop.
Konversi List<List<String>> ke String[][]
import java.util.List;
import static java.util.Arrays.asList;
public class ListUtil {
public static String[][] listToArray(List<List<String>> listOfString) {
String[][] retval = new String[listOfString.size()][];
int index = 0;
for (List<String> data : listOfString) {
String[] array = new String[data.size()];
data.toArray(array);
retval[index] = array;
index++;
}
return retval;
}
public static void main(String[] args) {
List<List<String>> data = asList(
asList("ak", "aw"),
asList("wa")
);
String[][] arrayOfData = listToArray(data);
int x = arrayOfData.length;
for (int i = 0; i < x; i++) {
if (null != arrayOfData[i]) {
int y = arrayOfData[i].length;
for (int j = 0; j < y; j++) {
System.out.print(arrayOfData[i][j] + "\t");
}
System.out.println();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment