Collection Framework in Java
Collection Framework in Java
OOPS in Jav
What is a Framewor
Exampl
Map interfac
Example
objects.
Java Collections can achieve all the operations that you perform on a data such as searching, sorting,
The Collection in Java is a framework that provides an architecture to store and manipulate the group of
objects
This Collection framework provides a set of interfaces and classes to implement various data structures and
algorithms.
What is Framework ?
Using frameworks saves time and reduces the risk of errors. You don't need to write everything from scratch.
It has Interfaces and its implementations, i.e., classes and the algorithm
Before the Collection framework was introduced, the standard methods for grouping Java objects were
Therefore, though the main aim of all the collections is the same, the implementation of all these collections
The Collection interface (java.util.Collection) and Map interface (java.util.Map) are the two main “root”
What is Framework ?
Here, we are seeing the hierarchy of List Interface and a similar hierarchy is followed for all Interfaces
The java.util package contains all the classes and interfaces for the Collections framework
It has interfaces that can have methods, but the methods declared in an interface are by default abstract
(only method signature, no body). Interfaces specify what a class must do and not how. It is the blueprint of
There are many implementations of each of the interfaces present inside Java Collection framework.
We will declare an arraylist, add elements to it, display all the elements, remove the third element, display the
final elements.
https://pastebin.com/4Z91cy57
MAP INTERFACE
The Map interface is present in java.util package represents a mapping between a key and a value.
The Map interface is not a subtype of the Collection interface.
Therefore it behaves a bit differently from the rest of the collection types.
A map contains unique keys.
There are two interfaces for implementing Map in java. They are Map and SortedMap, and three classes:
HashMap, TreeMap, and LinkedHashMap
A Map cannot contain duplicate keys and each key can map to at most one value.
The order of a map depends on the specific implementations. For example, TreeMap and LinkedHashMap
have predictable orders, while HashMap does not.
clear()
containsKey(Object)
containsValue(Object)
entrySet()
equals(Object)
get(Object)
isEmpty()
keySet()
put(Object, Object)
putAll(Map)
remove(Object)
values()
getOrDefault(Object
key, V defaultValue)
EXAMPLE:
Let’s use a HashMap to create key value pairs and display their values using java Map classes’ methods.
https://pastebin.com/TVHiDuMJ