Java Collection methods - Stack Overflow
Why java doesn't have collections literals?
Best Way to Learn Java Collection Framework
Having trouble understanding collection framework, need good source
Hopefully this analogy works.. Here we go!
Say you want to drink some liquid and you're deciding on a cup to use. You could grab a teacup, but it might be too small. You could use a plastic cup, but you might be pouring hot liquid that could burn you or melt the cup. Maybe you just want to store the liquid, you would probably want a cup that has a lid.
The collections framework is kind of like those cups. Yes, they all create some kind of lists, but it's about what you need the list for. If you need to insert/remove items at any point of the list, it's quick and easy to do in a linkedList as you don't need to resize your collection. If order matters you probably wouldn't want to use a hashMap, but if you wanted to avoid duplicates a hash map would be a potentially useful tool.
When it comes down to it, your job is to decide which "cup" is best for the job. You don't want a 64oz mug if you want a sip of water.
Consider reading about the differences between a set, a list, and a queue as those might give you more insight to how these tools are implemented! Hope this helps!
More on reddit.comVideos
The JDK designers wanted code like the following to be possible:
Collection<String> strings = Arrays.asList("foo", "bar", "baz");
Collection<Object> objects = Arrays.asList("foo", 123);
strings.removeAll(objects);
// strigns now contains only "bar" and "baz"
(The above code might not exactly compile because I can't remember how Arrays.asList() captures type parameters, but it should get the point across.)
That is, because you can call .equals() on any pair of objects and get a meaningful result, you don't really need to restrict those methods to a specific item type.
Because a E type parameter needs to be specified while a wildcard ? works for every type. The subtle difference is that
Emeans any specified type?means any unknown type
Since there methods are supposed to work on a collection of any unknown type then they doesn't specify a type parameter at all. E is a type variable. ? is not a variable, is a placeholder which cannot be specified.