My hashmap has String type as key and ArrayList type as value, example {"v1"=[1.1,1.2,1.3], "v2"=[2.1,2.2,2.3,2.4]} where "v1" and "v2" are keys. There are more than 40 keys (previously unknown size) and each key has a ArrayList which may not be uniform in size (size >200).
I want to write this hashmap data in the following format in a .csv file in my Android phone.
v1 v2
1.1 2.1
1.2 2.2
1.3 2.3
Until now, my Hashmap had fixed key/array size and I used the following code snippet to dump the data:
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
File folder = new File(Environment.getExternalStorageDirectory() + "/santobedi" + hour + "-" + minute + "-" + second);
String csv = folder.getAbsolutePath() + "/data.csv";
try {
file_writer = new FileWriter(csv, true);
if (isReady == false) {
String s = "v1, v2,\n";
file_writer.append(s);
isReady = true; // The columns heads are set
}
} catch (IOException e) {
e.printStackTrace();
}
Later, I'd append (row-wise) the values on a loop checking the Boolean value isReady. Now, the size of the key is not fixed, so I cannot set the column heads as before. I searched for a possible solution, this question is almost similar to my situation. However, it is not related to memory location inside the Android phone and the accepted answer is still not solving my problem.
Any help, please!