How to use Collection API? [closed]
I have a packet having fields :
Root Level : CHOICE
Level 1 : SET
Level 2 : SEQUENCE , CHOICE
Note : CHOICE :- You can have one available fields.
SET :- Fields can be in any order.
SEQUENCE : Fields are in specific order.
Assume each field has a unique id for specific level.
I want to read and then put in one one Collection API.
Can anybody suggest how to use MAP, SET or List in an efficient way?
SET > Set
(Tutorial)
SEQUENCE > List
(Tutorial)
CHOICE doesn't really have a mapping in the Collection API, but you could use AtomicReference
.
Your ability to use a structure in an efficient way is entirely dependent upon how you wish to access the data. If you want to be able to find a specific item according to a key, use a HashMap. If you want to be able to have an arbitrary list of items, use ArrayList. If you wish to be able to both access a specific item according to a key and be able to iterate all items like a list, use LinkedHashMap.
Though from what you're describing about a set of CHOICE, it seems to me you're talking about an enumerator. Enumerators are essentially static sets, and unless you intend on modifying your choices dynamically, I would suggest you use this rather than a Set.
精彩评论