• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic