tags:

views:

48

answers:

1

Hi,

I have created the csv file.The records are displaying row order.but i need coloumn order.

how 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);
}
A: 

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

seanizer
It is getting error, incompatible typesfor(Map<String, String> map : maps) {
Rose
OK, I was assuming that maps was an array of maps. If it isn't, maybe you should provide more code: what is maps and what is labels?
seanizer