Search code examples
javaarraysarraylistcollections

All-in-one Collection in Java


I am coming from PHP/laravel to JAVA/springboot.

In PHP we have only one type of collection which is called array that according to PHP community it's using hash table.

Java it have a lot of collections and when read about their advantage over each other it's confusing to know which one to use.

Is there any package or let's say a collection in java include all features for each type of collection it have and switch between those collection objects according to operation used as search, insert, update and delete.

and if not, What advice did you give to me, solution for using them ?


Solution

  • As a new user of Java you are likely being overwhelmed by the number of implementations of collections that are offered. You really don't need to worry about that too much to start with. Rather focus on the interfaces which describe how you plan to interact with the collection. There aren't too many of those. In fact there are really only three that you need to think about when you're starting to learn the language: List, Set and Map. Start by picking which of those makes sense for your application and then write all your code to that interface. Which implementation of the interface you use is in only one place - when the collection is constructed - and is very easy to change at a later time if you write for the interface.