What is the need of Collection framework in Java since all the data operations(sorting/adding/deleting) are possible with Arrays and moreover array is suitable for memory consumption and performance is also better compared with Collections.
Can anyone point me a real time data oriented example which shows the difference in both(array/Collections) of these implementations.
The Collection in Java is a framework that provides an architecture to store and manipulate the group of objects. Java Collections can achieve all the operations that you perform on a data such as searching, sorting, insertion, manipulation, and deletion.
Java Collections framework provides implementation classes for core collection interfaces. We can use them to create different types of collections in the Java program. Some important collection classes are ArrayList, LinkedList, HashMap, TreeMap, HashSet, and TreeSet.
Vector
but cooler), red-black trees, hash-based maps (like Hashtable
but cooler).List
, whether backed by an array list or a linked list; and you can refer to a map/dictionary as a Map
, whether backed by a red-black tree or a hashtable.In other words, Java Collections Framework allows you to use the right data structure, because one size does not fit all.
Several reasons:
Take a look at this fragment that illustrates the covariance problem:
String[] strings = new String[10];
Object[] objects = strings;
objects[0] = new Date(); // <- ArrayStoreException: java.util.Date
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With