0 votes
in JAVA by
Tell me few best practices you apply while using Collections in Java?

1 Answer

0 votes
by
Here are couple of best practices I follow while using Collectionc classes from Java:

a) Always use the right collection e.g. if you need non-synchronized list then use ArrayList and not Vector.

b) Prefer concurrent collection over synchronized collection because they are more scalable.

c) Always use interface to a represent and access a collection e.g. use List to store ArrayList, Map to store HashMap and so on.

d) Use iterator to loop over collection.

e) Always use generics with collection.

Related questions

0 votes
asked Oct 3, 2023 in Service Now by john ganales
0 votes
asked Jan 27, 2020 in JAVA by rahuljain1
...