0

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?

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by masijade
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.