• Post Reply Bookmark Topic Watch Topic
  • New Topic

which collection i can use  RSS feed

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends,

please tell me i want to use collections in my project.in which i will be reading xml and and want to store in collection class.......

i don't want duplicate key


pls sugest me
 
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In memory, XML is usually represented in a DOM tree, which preserves the hierarchical structure of XML. If you want to store it in a collection (why?), you first need to decide which element and attribute information should be on the first level, and which (if any) in nested collections on deeper levels. But since you mention keys, it seems that you have decided already that you want to use one of the implementations of the Map interface - is that correct?
 
vijay kumar
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya i am reading xml. i want to store the values in array which has to keys and one value.

example

- <collate>
- <data work-object-ref="06268001706-001">
<fv id="DOCUMENT">06268001706001001</fv>
<fv id="SEQUENCE">00000001</fv>
<fv id="CURSTAGE">C0</fv>
<fv id="VIEWNAME">HCFA</fv>
<fv id="FILEPATH">n:\indata\Wellpt\welb\20060925\02230293</fv>
<fv id="IFNAME01">02230293.027</fv>
<fv id="IFNAME02">02230293.028</fv>
<fv id="IFNAME03" />
<fv id="IFNAME04" />
<fv id="IFNAME05" />
<fv id="IFNAME06" />
<fv id="IFNAME07" />
<fv id="IFNAME08" />
<fv id="IFNAME09" />


in this fist tag value 06268001706001 as one key and id value(i.e document,seqy etc) as another key and tag information(i.e C0,HCFA etc) as a value
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you need to store it in memory ...

- just concat the keys and use a Map. Perhaps you need to add a separator so your key stays unique ?
key1 = "fo" key2 ="obar" -> concatted key = "foobar"
key1 = "foo" key2 ="bar" -> concatted key = "foobar"

if you add a separator (e.g. "fo-obar" / "foo-bar") this should work.

- or write a composite key class which holds the two keys and overrides equals/hashCode properly and use a Map.


pascal
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use any of the concrete implementations of Map interface depending upon your requirement.If many threads might use your collection then you might go for HashTable or if there is no multithreaded issue then you might consider hash map.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!