• Post Reply Bookmark Topic Watch Topic
  • New Topic

am i adding some unnecessary lines or collection in my code?  RSS feed

 
Punit Jain
Ranch Hand
Posts: 1066
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

After observing so many performance issues by not using proper collections in proper, now a days i think more right ways to using them.

Input - An XML or String in key and value format. i.e.



Output - A Map of keys and value, which i can use for comparison.

My code -



Here is the way i am calling this code -



Anything i can improve here?

Thanks,
Punit
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to provide some context. The obvious data structure for the XML you showed would be Map<String, String>, so what are you trying to achieve by using a Map<List<String>, List<String>>? A List<String> is a rather unusual key type for a Map.
 
Punit Jain
Ranch Hand
Posts: 1066
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, i might have a wrong thought here - i thought since i have a collection of keys and values (XML tags), so i will store them in the lists and later put those lists in map.
However i can remove the use of list here, and can directly put the key and values to the map, but the issue would be how would i put them (keys, values) into the map? i used two for loops in my code -


how do i iterate over two node list in single for loop? nested loops are also not a choice here.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I generally find DOM tedious and complicated to work with, so I might use a SAX parser so I'd get all the key and value elements in order.
 
Jayesh A Lalwani
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have designed your XML in a way that makes it harder for yourself. If it were

t


You could have got list of items and then iterated over it to get key and value
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!