How to display the records as columns?
I have created the csv file.The records are displaying row order.but i need coloumn order.
ho开发者_开发知识库w to modify the code ?
for(int i = 0;i < maps.length;i++) {
Map<String, String> map = (Map<String, String>)maps[i];
sep = "";
for(int j = 0;j < labels.length;j++) {
String val = map.get(labels[i]);
out.write(sep);
out.write(""+val);
sep = ",";
}
out.write(LINEFEED);
}
First of all, you should use new-style loops, they are much clearer and prettier:
for(Map<String, String> map : maps) {
sep = "";
for(String label: labels){
out.write(sep);
out.write(map.get(label));
sep = ",";
}
out.write(LINEFEED);
}
then, you just need to switch inner and outer loops
for(String label: labels){
sep = "";
for(Map<String, String> map : maps) {
out.write(sep);
out.write(map.get(label));
sep = ",";
}
out.write(LINEFEED);
}
that should switch from rows to columns
精彩评论