How to choose Collection in Java? List, Set, Map, and Queue Example

General Linux topics
Post Reply
admin
Site Admin
Posts: 50
Joined: Sun Aug 08, 2021 7:49 am

How to choose Collection in Java? List, Set, Map, and Queue Example

Post by admin »

The Java collection framework gives implementation of different records shape like an array, list, set, map, queue, tree, and many others and the choice absolutely relies upon upon the state of affairs and residences of the unique facts shape. For example, in case your requirement is fast seek with index then you could use ArrayList and in case you need to keep key-fee pairs you then would bear in mind using hash desk records shape and there are more than one implementation of hash table statistics structure in Java, like HashMap, Hashtable, LinkedHashMap, TreeMap, and ConcurrentHashMap. Now, which one will you pick out? If you do not know or careworn do not worry, i can come up with a hard and fast of policies and use instances a good way to help you choose the right collection kind in Java depending upon situation.
Post Reply