java : set arraylist, maps, sets, hashmaps

hello experts
I am new to Java
I am really too confused about all types that allow to store objects and data like
Arrays, sets, Map, hashmap, ArrayList, lists, tree etc...

Can someone tell me what are the most usefull (the 3-4 I will use in my projects) and in what case should I use this one rather then anorther one ?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Java Collections (I strongly recommend reading contains several types. The main ones I work with are:

List interface (most common implementation is ArrayList) - a simple list of items with an order. You can insert an item anywhere in the list, take an item from anywhere in the list, etc.
An example for using a List is keeping all the lines from a file you read in a List<String>, each line at its appropriate index.

Set interface (msot common implementation is HashSet) - a simple Set of items. The main differences from List is the fact that a set doesn't have  inherent indexes for its items, is HashSet there is no guaranteed order for going over items, and can only hold one copy of items that are logically equal.
An example for using a Set is building a dictionary of all the words from a text in Set<String>. Note that even if a word appears more than once in the text, the Set<String> will only hold one copy of that string.
Some more implementations for set:
LinkedHashSet - in which the order of items you get from the set is identical to the order you insert them into it
SortedSet (interface) - A set where the items are kept sorted. If you're using classes which do not have a comparator to compare them, you'll have to create one.

Map interface (e.g., HashMap) - A map containing keys and values. Each key can only appear once.
Keeping all the words from a text with the number of times they appear in the text using a Map<String, Integer> where the key is the word and the value is the number of appearances.
Keeping all the people in company according to their employee ID, to allow fast access to an employee using his/her id: Map<String, Empoyee> where the key is the ID string.

Please note that when using Set/Map you may need to think about implementing hashCode() and equals() to the classes you use.
There are of course other collections (Queue, HashTable, Vector, Stack) but these are the most common ones.

One more thing - if you use collections, take a look at java.util.Collections class, it has some very useful static methods.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
>Can someone tell me what are the most usefull (the 3-4 I will use in my projects)

If there was an answer to that question, there would not have been all of the rest, don't you think?

ozlevanon already gave you a great answer. If you are interested, here are also some code examples that come handy sometimes:
and the proverbial of course.

And is a nice thing :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.