Java List:
If you do not have such a requirement, you should duplicate it or not. Then you can use List instead of Set.
A list is an interface within a collection. Which extends the Collection interface. and ArrayList, LinkedList is an implementation of the List interface.
When to use ArrayList or LinkedList
ArrayList:. If you have such a requirement, your data access mainly works in your application. Then you should go to ArrayList. because ArrayList implements the RtandomAccess interface, which is the token interface. due to the Marker interface, ArrayList has the ability to access data O (1) times. and you can use ArrayList for LinkedList where you want to get the data according to the insertion order.
LinkedList: If you have such a requirement that your main job is to insert or delete. Then you should use LinkedList over ArrayList. because in LinkedList insertion and deletion occur O (1) times, whereas in ArrayList it is O (n) time.
Java Set:
If you have a requirement in your application that you do not need duplicates. Then you should go to Set instead of List. Because Set does not store duplicates. Because Set works on the principle of Hashing. If we add an object to Set, then first it checks the hashCode object in the bucket, if it finds any hashCode present in it, bucked, then it will not add this object.
Vpn_talent
source share