I have a List which hold an Array List and I want it to be converted into multidimensional array:
/*
The logs looks something like this
[Name: Foo, From: Somewhere, To: Somewhere]
[Name: Foo1, From: Somewhere1, To: Somewhere1]
[Name: Foo2, From: Somewhere2, To: Somewhere2]
...
*/
public static void main(String[] args) {
List<ArrayList<String>> items = new ArrayList<>();
for (String logs : Reader.read(App.purchaseLog, true) /* helper method */) {
String[] singleLog = convert(logs); /* helper method */
items.add(new ArrayList<String>());
for (String data : singleLog) {
String removeBrackets = data.replaceAll("\\[", "").replaceAll("\\]", "");
String[] splitSingleLog = convert(removeBrackets.split(","));
for (String element : splitSingleLog) {
String trimmedData = element.trim();
items.get(0).add(trimmedData.substring(trimmedData.indexOf(':') + 2, trimmedData.length()));
}
}
}
// But then how can i convert it to normal 2 dimensional array?
// i am expecting it to be like this
String[][] data = {
{"Foo", "Somewhere", "Somewhere"},
{"Foo1", "Somewhere1", "Somewhere1"},
{"Foo2", "Somewhere2", "Somewhere2"}
};
}
public static String[] convert(String... array) {
return array;
}
How can i loop each ArrayList to change it into normal array? I saw several examples on converting ArrayList into an array but it's mostly 1 dimensional array (Convert ArrayList<String> to String[] array)