Hello,

Currectly I was doing an assignment where I was connecting to remote unix boxes from a windows system and some response from them. The response is something like

att1,att2,att3,att4\n
val01,val02,val03,val04\n
val11,val12,val13,val14\n
...
...

This response comes to me as a long StringBuffer.
Then I have to render the response into an excel sheet or a webpage... whatever is asked.

Method 1:
I split it at "\n" to get the rows[] and then each row is split at "," to get the cols[]. Then use nested loop structure to write out each value, like:

for(...){
// Loop through rows
[INDENT]
for(...){
// Loop through cols
}
[/INDENT]
}

Method 2:
-------------
I can make a Map for the attributes and values. A Map ll contain values for 1 row with attributes as keys. Then a list of all these maps.

then the o/p can be rendered in a single loop:

for(...){
//loop through all the maps
output val 1
output val 2
.
.
.
}

How much difference is there in the performance of 2 methods?
Which method is preferrable?

Give it a try, but remember that if you need to retreive the "rows" from the Map in the same order in which you inserted them, then make sure you use a LinkedHashMap, and not a standard HashMap or TreeMap

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.