Collection Framework
Collection Framework
Collection:
- A collection is simply an object that represents a group of objects.
Collection framework:
- It provides a set of classes and interfaces that helps in managing a
group of objects.
What is the difference between Collection and Collections?
Collection is an “interface” which can be used to represent a group of
objects as a single entity.
Whereas “Collections is an utility class” present in java.util package to
define several utility methods for Collection objects.
Memory point of view arrays are not Memory point of view collections
recommended are recommended
Arrays can hold both primitive and Collections can only hold object but
object types. not primitive types
LIst
====
ArrayList :
jIt is a resizable array implementation of the List interface.Unlike arrays,
which has fixed size, an ArrayList can change its size dynamically as
elements are added or removed. this makes it a popular choice hwen the
number of elements in a list isn’t known in advance.
Legacy Yes No NO
Null is allowed for key and value. Null is not allowed for both key and
value otherwise we will get NPE
Enum vs inheritance:
• Every enum in java is the direct child class of java.lang.Enum class hence
it is not possible to extends any other enum.
• Every enum is implicitly final hence we can’t create child enum.
• Because of above reasons we can conclude inheritance concept is not
applicable for enum’s explicitly.