Java Collections Framework-Part2 | Interfaces And Classes

SDET- QA
22 Sept 202027:45

Summary

TLDRThis video script offers an in-depth exploration of Java's Collection Framework, emphasizing the foundational Collection interface and its derived interfaces: List, Set, and Queue. It distinguishes between them based on their handling of insertion order and duplicates. The script also introduces the distinct Map interface, which stores data as key-value pairs with unique keys. It briefly mentions utility classes like Collections and outlines various collection classes such as ArrayList, LinkedList, HashSet, and HashMap, setting the stage for实操 demonstrations in upcoming videos.

Takeaways

  • 📚 The Java Collection Framework is a set of interfaces and classes that allow for the manipulation and storage of groups of objects.
  • 🔑 The root interface in the Collection Framework is the Collection interface, which provides a set of common methods for all collection objects.
  • 🧩 The Collection interface is extended by several child interfaces including List, Set, and Queue, each with specific characteristics for different use cases.
  • 📝 List interface maintains the order of elements and allows duplicates, suitable for scenarios where insertion order is important.
  • 🚫 Set interface does not maintain the order of elements and does not allow duplicates, ideal for unique element storage without order concerns.
  • 📬 Queue interface follows the First-In-First-Out (FIFO) principle, used for processing elements in the order they were added.
  • 🔄 The Collections class in Java provides utility methods to manipulate any collection, such as sorting, searching, and shuffling.
  • 🔗 The Map interface is distinct from the Collection interface and is used for storing data in key-value pairs, with keys being unique.
  • 📦 Classes like ArrayList, LinkedList, HashSet, and PriorityQueue implement various collection interfaces, providing different functionalities and performance characteristics.
  • 🔍 The choice of collection interface and implementing class depends on the specific requirements of data storage and manipulation, such as order preservation, uniqueness, and access patterns.

Q & A

  • What is the primary role of the Collection interface in Java's Collection Framework?

    -The Collection interface serves as the root interface for all collection-related classes and interfaces in Java. It provides a set of common methods that can be used across various collection objects, such as adding, removing, and checking for the presence of elements within the collection.

  • How does the Collections class in Java differ from the Collection interface?

    -The Collections class is a utility class within the java.util package that contains static methods to operate on or return various collection types, such as sorting a list. It is not an interface but a class that provides additional functionality to manipulate collections, whereas the Collection interface defines the contract for collection types.

  • What is the significance of the List interface in the Java Collection Framework?

    -The List interface is a child of the Collection interface and is used when the order of elements is important. It allows duplicate elements and maintains the insertion order, meaning elements are preserved in the order they were added.

  • Which Java classes implement the List interface and why would you use them?

    -Classes that implement the List interface include ArrayList, LinkedList, Vector, and Stack. You would use these classes when you need to maintain the insertion order of elements and allow duplicates, with each class offering different performance characteristics and capabilities.

  • What is the Set interface and under what conditions should it be used?

    -The Set interface is also a child of the Collection interface and is used when you want to store unique elements without maintaining any order. It does not allow duplicates, and the insertion order is not preserved.

  • Can you name the classes that implement the Set interface in Java?

    -The classes that implement the Set interface in Java are HashSet and LinkedHashSet. These classes are used when you need to ensure that all elements are unique and the order of elements is not a concern.

  • How does the Queue interface differ from the List and Set interfaces?

    -The Queue interface is different from List and Set interfaces as it represents a collection designed for holding elements prior to processing, following a first-in, first-out (FIFO) order. It is typically used for managing tasks in the order they were received.

  • What is the primary use case for the PriorityQueue class in Java?

    -The PriorityQueue class is used when you need to manage a collection of objects where each object has a priority associated with it. It ensures that the highest priority object is always at the front of the queue and is served first.

  • What is the Map interface and how does it differ from the Collection interface?

    -The Map interface is a separate and independent interface in the Java Collection Framework. It stores elements in key-value pairs, where each key is unique but values may not be. It is not a child of the Collection interface and is used when you need to associate values with unique keys.

  • Which classes in Java implement the Map interface and what are their主要用途?

    -The classes that implement the Map interface in Java are HashMap and LinkedHashMap. HashMap is used for fast access to values based on keys, while LinkedHashMap maintains the insertion order of the keys.

Outlines

00:00

📚 Introduction to Java Collection Framework

The speaker begins by welcoming the audience and referencing the previous video where the basics of Java collections and the collection framework were introduced. The focus of this session is to delve into the interfaces and classes within the collection framework. The Collection interface is highlighted as the root interface for all collection-related classes and interfaces, providing common methods for collection objects. The concept of a collection as a group of objects represented as a single entity is explained, with examples such as a list of employees. The common operations that can be performed on collections, like adding, removing, and checking for the presence of objects, are discussed. The Collections class from the java.util package is introduced as a utility class containing methods that operate on collection objects, such as sorting an ArrayList.

05:04

🔗 Understanding the Collection and Collections Classes

The speaker clarifies the difference between the Collection interface and the Collections class in Java. While Collection is an interface that provides a structure for creating collections, Collections is a utility class that includes methods to manipulate collections, such as sorting. The session continues with an example of sorting an ArrayList using the Collections.sort() method, illustrating practical usage. The speaker emphasizes the importance of understanding the distinction between the Collection interface and the Collections class for effective Java programming.

10:08

📋 Exploring List Interface and Its Implementations

The speaker moves on to discuss the List interface, which is a child of the Collection interface. The List interface allows for the insertion of objects while maintaining the order in which they were inserted, and it permits duplicates. Examples of classes that implement the List interface are provided, including ArrayList, LinkedList, Vector, and Stack. The speaker explains that these classes are used when the order of elements and the allowance of duplicates are important considerations for the collection.

15:12

🚫 Set Interface and Its Unique Characteristics

The Set interface is introduced as another child of the Collection interface, with a focus on its unique properties. Unlike the List interface, the Set interface does not preserve the insertion order and does not allow duplicates. This makes Sets ideal for scenarios where uniqueness and no specific order are required. The speaker mentions HashSet and LinkedHashSet as classes that implement the Set interface.

20:12

📬 Queue Interface for Processing Order

The Queue interface is explained as a child of the Collection interface, designed for handling objects that need to be processed in a specific order, typically a first-in, first-out (FIFO) approach. The speaker uses the example of sending emails to illustrate the concept of 'prior to processing.' The Queue interface is implemented by classes like PriorityQueue, which is highlighted as a key class for managing objects in a queue.

25:15

🗂️ Map Interface for Key-Value Pairs

The speaker concludes with an introduction to the Map interface, which is independent of the Collection interface. The Map interface allows for the storage of objects in key-value pairs, where keys must be unique, but values can be duplicated. Examples of classes that implement the Map interface include HashMap and LinkedHashMap. The session wraps up with a summary of the different interfaces and classes discussed, emphasizing their unique characteristics and use cases within the Java collection framework.

Mindmap

Keywords

💡Collection

A collection in the context of the video refers to a group of elements that can be represented as a single entity. It is a fundamental concept in Java's Collection Framework, which provides a structured way to store and manage groups of objects. The video script uses the example of an organization's employees, where multiple employee objects can be treated as a single collection entity. This concept is essential for understanding the organization and manipulation of data in Java programs.

💡Collection Framework

The Collection Framework in Java is a vast architecture of interfaces and classes that facilitate the handling of collections of objects. It provides a unified interface to different types of collections, such as lists, sets, and queues. The video emphasizes that the Collection Framework is crucial for managing data structures in Java, offering a variety of methods for adding, removing, and checking objects within collections.

💡Interface

In Java, an interface is a reference type that is used to specify a contract that classes can implement. In the video, interfaces like Collection, List, Set, and Queue are discussed as part of the Collection Framework. These interfaces define methods that must be implemented by any class that claims to implement the interface. For instance, the Collection interface is described as the root interface for all collection-related classes and interfaces, providing common methods for collection objects.

💡ArrayList

ArrayList is a class in Java that implements the List interface. It allows the creation of a dynamic array that can grow and shrink as needed. The video script mentions ArrayList as one of the classes that implement the List interface, which is used when the insertion order of elements needs to be preserved and duplicates are allowed. It is a versatile and commonly used class in Java for managing lists of objects.

💡LinkedList

LinkedList is another class in Java that implements the List interface. Unlike ArrayList, which is based on a dynamic array, LinkedList uses nodes to store elements, making it more suitable for frequent insertions and deletions. The video script includes LinkedList as an example of a class that implements the List interface, highlighting its utility in scenarios where the order of insertion is important.

💡Set

The Set interface in Java is part of the Collection Framework and represents a collection that cannot contain duplicate elements. The video explains that Sets do not maintain the order of elements, which is a key difference from Lists. Sets are useful when uniqueness of elements is a priority, and the video uses the concept of a Set to illustrate how collections can be used to store unique objects.

💡Queue

Queue is an interface in Java that represents a collection designed for holding elements prior to processing. It follows a first-in, first-out (FIFO) approach, which is essential for managing sequences of tasks or data. The video script uses the example of sending emails to a list of recipients, where the order of sending is based on the order of insertion into the collection, illustrating the use of the Queue interface.

💡Map

Map is an interface in Java that is distinct from the Collection interface. It stores elements in key-value pairs, where each key is unique but values may not be. The video script explains that Map is used when you need to associate data items with unique identifiers, such as looking up employee details by their ID. The Map interface is implemented by classes like HashMap and LinkedHashMap, which provide various ways to manage key-value pairs.

💡HashMap

HashMap is a class in Java that implements the Map interface. It stores data in key-value pairs and provides efficient insertion, deletion, and access operations. The video script mentions HashMap as a class that implements the Map interface, emphasizing its utility in scenarios where quick lookups are necessary due to its underlying hash table data structure.

💡LinkedHashMap

LinkedHashMap is another class in Java that implements the Map interface, similar to HashMap. However, it maintains a linked list of the entries in the order they were inserted, thus preserving the insertion order. The video script includes LinkedHashMap as an example of a Map implementation that can be used when the order of elements is important, in addition to the key-value storage.

Highlights

Introduction to the Java Collection Framework and its various interfaces and classes.

Explanation of the root Collection interface and its role in the framework.

Description of the common methods available in the Collection interface for all collection objects.

Discussion on the concept of a Collection as a group of objects represented as a single entity.

Introduction to the Collections class in the java.util package and its utility methods.

Example of using the Collections.sort method to sort elements in an ArrayList.

Differentiation between the Collection interface and the Collections class.

Overview of the List interface as a child of the Collection interface.

Characteristics of the List interface: preservation of insertion order and allowance of duplicates.

Introduction to the Set interface as another child of the Collection interface.

Characteristics of the Set interface: no preservation of insertion order and no allowance of duplicates.

Introduction to the Queue interface and its use for representing objects that are prioritized for processing.

Explanation of the First-In-First-Out (FIFO) concept in Queues.

Introduction to the Map interface and its use for storing objects in key-value pairs.

Characteristics of the Map interface: uniqueness of keys and allowance of duplicate values.

Overview of the different classes implementing the List, Set, and Queue interfaces.

Introduction to the classes implementing the Map interface, such as HashMap and LinkedHashMap.

Summary of the Collection Framework's interfaces and their respective use cases.

Announcement of future videos demonstrating practical usage of the Collection Framework's interfaces and classes.

Transcripts

play00:01

hi everyone welcome you all in our previous video  we have seen what is collection and what is the  

play00:07

collection framework and what are the differences  between collection and collection framework  

play00:11

now i have told you like collection framework  is basically contains n number of interfaces and  

play00:16

classes right so first of all let us see what are  the different interfaces and classes are available  

play00:21

and then we will see each and every class in  interface in detail so in the today session the  

play00:26

mainly focusing on what are the main interfaces  and what are other derived classes are available  

play00:31

in the collection framework so the first  and most important collection framework  

play00:36

in the main interface in the  collection framework is collection  

play00:40

interface so the name of the interface is  collection so basically this is an interface  

play00:46

so this collection is a root interface we can  simply call as a root interface for all other  

play00:51

collection related classes and interfaces and  which contains a common methods which we can use  

play00:57

for other collection objects so for example we  have understood what is collection rights what  

play01:02

is a collection means a group of elements we can  represent a group of elements as a single entity  

play01:08

so for example i have an organization in  employees let's say i have emp one object  

play01:13

mp2 object i have emp3 object and so on so there  are multiple objects i have i'll representing all  

play01:20

objects as a single entity so this is a single  entity this is basically we can do by using a  

play01:27

collection so collection is nothing but a group of  objects together we can call as a group of object  

play01:33

is a collection so to representing this collection  we need certain interfaces and classes right  

play01:41

so if i just look at here we have multiple objects  representing with single entity here right so  

play01:48

what are the common operations we'll do on these  objects normally when i have some collection here  

play01:53

we add some object into this collection or we  want to remove this collection from this remove  

play01:59

this object from the collection and sometimes we  can check whether the object is present inside  

play02:05

the collection or not so these are the common  operations we can do on the collection so to do  

play02:12

these operations like these operations are common  for all kinds of collections so adding a new  

play02:18

object or removing an object or we can verify the  existing object which whether is available inside  

play02:24

the collection or not so all these things we  can do by using certain methods so those methods  

play02:30

are commonly have across all the collection  classes so those methods are present inside the  

play02:37

collection interface so the collection interface  is used to representing group of objects as a  

play02:44

single entity and which contains a common methods  which are required for other collections so most  

play02:50

of the times the methods which are defined inside  the collection interface are common across all the  

play02:56

collection classes so this is the first and most  important collection we have as part of collection  

play03:02

framework so this is a collection interface now  in java we have something called collections  

play03:11

so what is collections so this is i'm talking  about collection this is purely an interface  

play03:16

now apart from this we also have one more thing  called collections so what about this collections  

play03:25

so collection is a group of elements we can  represent multiple objects as a single entity  

play03:30

which is a collection and the collection if you  want to create we can use a collection interface  

play03:35

so we'll get all the method from this but what is  about what about the collections so collections in  

play03:41

java which is actually a class from java dot utils  package so in java we have a java.utils package  

play03:51

so the collection is a class which is present  inside the java.utils class utils package so what  

play03:56

basically correction class contains collections  class also contains certain methods and these  

play04:03

methods we can use for collection objects so the  collections is a pre-different class which is  

play04:10

available inside the java.util package in java so  we can use this collections class contains certain  

play04:16

number of methods and those methods we can use to  perform certain operations on collection objects  

play04:23

now let me show you one example here so to  understand this and let's take a small arraylist  

play04:30

object so let me just create one arraylist let us  say ar i have an error list and i want to i have  

play04:38

some elements in the arraylist so element1 and  2 and element 3 are these are different objects  

play04:44

so i want to sort all these objects or i want  to sort all these elements inside the array list  

play04:50

so error list is a basically a collection object  now to sort all these elements what you can do is  

play04:57

we can use a collections class so we have a class  called as a collections from java.util package  

play05:04

inside this collection we have a method called  sort and we can pass this array list here and  

play05:11

then what happens the collections inside this  class we have a sort method which is a utility  

play05:16

method we have and that particular method will  sort the elements inside the error list so what  

play05:22

we have to understood here is the collections is  a a predefined class which is available inside the  

play05:27

java.util package and which is providing certain  number of methods and those methods we can use  

play05:34

to perform certain operations on the collection  objects so here the collection is an interface  

play05:40

collections is a a predefined class which is  available inside the collections.java.util package  

play05:48

okay so like this like a sort method we  have a n number of methods are available  

play05:52

in the collections class and we can use those  methods to perform certain operations on the  

play05:57

collection object so this is a basic difference  between collection and collections now collection  

play06:04

and the collections let me just  repeat once again so collection is  

play06:08

an interface which is comes under collection  framework and collections is a predefined class  

play06:14

which contains some utility methods by which we  can perform certain operations on the collection  

play06:20

objects so that is the difference between  collection interface and collection collection  

play06:31

collections this is a class okay so collection  is an interface collections is a class and which  

play06:37

contains the methods and these methods we  can use for collection objects to perform  

play06:42

certain operations so this is a very very  important thing so collection is a first and  

play06:48

root interface which contains the methods which  we can use commonly across collection classes  

play06:54

now this is the first interface from this  interface we have different type of interfaces  

play07:02

created and again those interfaces are  implemented by different number of classes  

play07:07

now let us see what are other interfaces we have  as part of collection framework and what are other  

play07:13

classes are available which are implemented those  existing interfaces in the collection framework so  

play07:19

now we discussed the collection interface so the  collection interface is a base interface we have  

play07:27

in the collection framework so this particular  collection interface this is a basically interface  

play07:33

which is having a child interfaces so the main  interface here is list is one interface and  

play07:43

we have also set interface set is also one  more interface list interface set interface  

play07:50

and we also have queue interface so these  are the main three interfaces which have  

play07:57

created as part of child of collection interface  so list is interface of the child of collection  

play08:03

interface set is another interface which  is also child of collection interface  

play08:07

and q is another interface which is also shield  of the collection interface again each and every  

play08:13

interface is uh implemented by using different  classes so we will discuss those classes later  

play08:18

so let us first focus on what are the main  interfaces we have in the collection framework  

play08:24

now let us see one by one so collection is a main  interface is a parent interface and this interface  

play08:31

again implemented there are chain interfaces  list to set and queue interfaces so these three  

play08:36

interfaces are jail interfaces of collection  so now we will discuss what exactly list  

play08:42

set and queue interfaces and what are  other classes which are available for  

play08:47

implementing these interfaces so first  let us start with the list interface okay  

play08:55

so first let us start with the list interface  okay so list so list is a interface which is  

play09:02

a child interface of the collection interface so  root interfaces collection right it's a collection  

play09:10

and list is a shared interface of the collection  so list is a child interface of the collection  

play09:17

now what is exactly list me so this is also  an interface so the first point is the list  

play09:24

is a child interface of the collection interface  and whatever methods we have in the collection  

play09:30

the same methods are also available in the list  interface and the second point is list is a chain  

play09:36

class of child interface of collection interface  the second first point list is child of collection  

play09:48

collection interfaces the first point the  second point is when we have to use a list  

play09:54

interface so this particular list interface we  can use suppose i have a group of objects let  

play10:01

us say i have a group of objects i want to store  all of them as a one entity so that is basically  

play10:07

called as a collection right so i want i have  a group of objects i want to store all of them  

play10:13

as a single entity now my requirement is i want  to store all these elements in the sorted order

play10:26

okay i want to store all the elements in  the sorted order so for example let us say

play10:34

here if i take group of elements in whichever  order we have inserted all the elements into this  

play10:43

element in the collection in the same order  it should preserve so for example let us say  

play10:49

i have taken one collection let  us say this is my collection  

play10:53

and i am going to insert multiple  objects into this collection  

play10:57

so whenever i add a new object the insertion in  whichever order i have inserted all the objects in  

play11:03

the same order it should insert so that means the  insertion order should be preserved okay so when i  

play11:10

add a new insert a new element that should be here  so this particular collection should maintain the  

play11:17

uh inserted insertion order should be  preserved so in whichever order we have  

play11:21

inserted these elements or objects in the  same order it should present so that's a  

play11:26

important thing so here in that particular case we  use list interface so if you want to add a group  

play11:32

of objects then suppose the insertion order should  be preserved and at the same time duplicates also  

play11:42

duplicates also allowed there is another point the  first point should be insertion order should be  

play11:48

preserved at the same time duplicates also should  allow in those two cases we go for list concept  

play11:56

so here insertion order preserved so this is the  first thing and the second thing is duplicates  

play12:09

duplicates a lot so in these two cases we will  prefer to use list concept so what is list means  

play12:16

a list is a a collection which we can store a  group of elements or objects but in that case  

play12:23

when we have to go for list if you want to add  all the group if you want to maintain all the  

play12:27

group of elements in the collection and where the  insertion order should be present insertion order  

play12:33

should be preserved so which in whichever way we  have inserted all the elements or objects in the  

play12:37

same order it should maintain the second point  is duplicates also allowed here so if you want  

play12:43

to insert another element same object again it  should allow us so in these two cases we go for  

play12:49

list concept so this is one of the collection  we have and the list is a jail interface of  

play12:55

collection interface now so what are the classes  are available which are implemented this list  

play13:01

interface so now we'll discuss about those classes  so list interface is implemented by using a  

play13:08

different classes let me just rub this so list  is an interface right interface alone we cannot  

play13:15

directly access so we have a certain number of  classes or implemented this list interface so what  

play13:21

are the different classes have implemented this  interfaces the first class is a released class  

play13:29

a released is a class which is implemented  all the methods which are available in the  

play13:34

list interface and the next one is linked list  arraylist linked list so this is another class  

play13:43

which is implemented this list the first one is  arraylist is a class linked list is another class  

play13:49

and we also have something called vector so  this is also another kind of a collection and  

play13:56

again this is implemented this is extended from  the stack so these are all different classes which  

play14:02

are implemented this list interface and list is a  child interface of collection and j list interface  

play14:09

is implemented by using different classes so error  list is one class linked list is another class  

play14:16

vector and stack so these are also classes and  these are called as a legacy classes from the  

play14:21

old versions of java you can find them so we can  call them our vector and stack is a legacy classes  

play14:27

so legacy classes so these are the classes  are available which are implemented  

play14:32

based on the list interface and list  interface is a jail interface of the  

play14:36

collection so so far we have seen two interfaces  in the aspect of collection framework so one is  

play14:43

collection interface there is a parent  interface for all other collections  

play14:47

inside the collection interface we have a  common methods which are required which are  

play14:51

useful for all other collection objects and  the second interface is a list interface and  

play14:57

which is derived from the collection interface  so this is the channel interface of collection  

play15:02

and when we need to go for list suppose if  you want to store a group of elements and  

play15:07

those elements when i add a new elements or when  i insert a new elements the insertion order should  

play15:12

be preserved and the second thing is duplicates  also should be allowed in those two cases  

play15:17

we will go with the list interface concept and  the list is implemented by using arraylist class  

play15:22

linkedin list class and vector and stack classes  so these are the set of classes are available  

play15:28

which are implemented list interface now apart  from this list interface there are some other  

play15:35

channel interfaces also there for collection  interface now we will discuss so we have seen  

play15:41

what is the list interface and when we need to  go for list interface now i will talk about other  

play15:49

type of collection that is set interface  so set interface is also derived from the  

play15:57

collection so set is also an interface set is also  an interface and this is again chilled interface  

play16:05

of the correction interface list set is also  channel interface of the collection interface  

play16:11

now so when we need to use set interface so when  you go for a list interface are two options one is  

play16:18

the insertion order should be preserved the  second point is duplicates also should be  

play16:23

allowed in those cases we have preferred the  list now here in the set interface the first  

play16:30

thing is insertion order not present insertion  order not present insertion order not preserved

play16:46

okay so in whichever way we have inserted  those elements it will not maintain the  

play16:51

same order inside the collection so insertion  order not preserved and the second point is  

play16:58

duplicates duplicates not allowed duplicates not  allowed so in that list the duplicates should be  

play17:09

allowed but in the set duplicates are not allowed  so when we need to go for set interface the first  

play17:16

thing is insertion order is not preserved and  duplicates are not allowed if i add one object we  

play17:22

cannot add the similar object again and again so  the duplicates are not allowed in these two cases  

play17:28

we go with the set interface and this is also  a child interface of collection interface now  

play17:36

what are the other classes which are  implemented based on the set interface  

play17:41

so now let us see what are those classes so the  set interface is implemented by using a class  

play17:47

called hash set so this is one class we have  and the same interface is implemented by using  

play17:55

another class called linked has a shirt linked  hash set linked let me write once again so here

play18:07

linked hash so this is another class we have  so these are the two classes have implemented  

play18:16

set interface set interface so when we need  to go for set interface set interface you  

play18:22

can be used whenever the insertion order not  preserved we don't want to preserve any insertion  

play18:28

order then we can go for the set and duplicates  also not allowed so in the set duplicates also  

play18:34

not allowed in these two criterias we can go  and prefer to use set interface so this is  

play18:41

one more interface we have which is part of the  collection interface so far we have discussed two  

play18:51

main interfaces which are chilled interfaces  of collection interface so what are those  

play18:58

interfaces the first one we have discussed about  a list interface the second one we have discussed  

play19:04

about set interface and these two interfaces are  derived from the collection interface itself now  

play19:10

what are the differences we have observed the list  inside in the list in case of list insertion order  

play19:19

insertion order should be preserved but in  case of set it is not preserved in case of list  

play19:26

duplicates are allowed or not duplicates  allowed but in case of set duplicates are  

play19:33

not allowed so these are the two differences  between the list and the set collections which  

play19:38

are derived from the same interface which  is a collection now apart from this list  

play19:45

and set there is one more interface which is  also derived from the collection interface  

play19:49

now we will see that collection so  the next interface is apart from this  

play19:56

a list and set we also have one more called q q  is also an interface so q is also an interface  

play20:06

and which is also implemented which is also  extended from the collection interface so this  

play20:12

is a parent and this is a child interface just  like a set and list queue is also another child  

play20:18

of the collection interface now when we need to go  for the queue so when we need to prefer the queue  

play20:25

so q is we can use a cube whenever you  want to representing a group of objects  

play20:31

which are prior to processing which are prior to  processing so what is meant by prior to processing  

play20:37

suppose i maintain different objects as a group  and these objects should be prior to processing  

play20:44

so then we can go for the queue so  what is prior to processing means  

play20:49

so let us try to understand it is basically first  in first out concept so here i have different  

play20:57

list of emails okay i have different list  of emails let's say i have a thousand emails  

play21:03

okay i have a thousand emails total 1000 emails  list i have right so 1000 emails list i have i  

play21:11

want to send an email i want to send an email  to all these people and the list of recipients  

play21:17

okay so when i compose when i send this email and  put all these email address in my cc list okay so  

play21:24

then what happens is this email will not go to  everyone at the same time so first it will send  

play21:30

to the first guy and second third fourth and fine  right so there will be a queue will be maintained  

play21:36

and uh the emails will be sent to image same email  will be sent to multiple people one after another  

play21:41

so this is a basically called as a uh this is  basically called as a prior to processing so  

play21:48

here there is a list of email ids we have so these  are prior to processing so here basically first in  

play21:55

first out concept so whichever first is in  and this that will be first out so first in  

play22:00

and first out so the queue is an interface we can  use whenever you have a objects which are prior to  

play22:10

processing which are prior to processing so then  we will prefer queue concept so this is also one  

play22:16

of the interface uh child interface of collection  interface now what are the different classes are  

play22:23

available which are implemented this q interface  so q interface is implemented one class called  

play22:31

priority queue so there are another classes also  there but here i'm just writing the main classes  

play22:36

which we are going to use very frequently so here  priority queue is there so this is the class which  

play22:43

is implemented this particular interface okay  q interface so these are the uh few interfaces  

play22:50

we have in the collection framework all the  interfaces are jailed interfaces of collection  

play22:55

interface now let me just summarize what are  the interfaces we have discussed so far which  

play23:01

are comes under collection interface the first  interface we have discussed is list interface  

play23:08

the second interface we have discussed is set  interface the third one we have discussed is  

play23:14

queue interface and the list interface will  be preferred if you have a group of objects  

play23:19

where insertion order preserved and duplicates  are allowed then we can go for list interface  

play23:25

list collection and suppose i have a group of  elements or group of objects where insertion order  

play23:31

not preserved duplicates also not allowed then  we can go for set interface and suppose i have a  

play23:38

group of elements which are prior to processing  then we can go for queue interface and again  

play23:44

each interface is implemented by using different  classes okay so these are all basic interfaces we  

play23:50

have under collection interface now apart from  this apart from these all interfaces there is  

play23:58

another interface we have called map interface  that is a completely independent interface of  

play24:03

collection that is nowhere related to collection  collection interface is one side let us say here  

play24:09

we have seen collection interface this so again in  the collection interface we have seen a list set  

play24:17

and the queue so these are the interfaces we have  seen apart from this there is one more independent  

play24:24

interface we have called as a map so  this is a different kind of interface  

play24:28

and this is not a child interface of the  collection interface so map is a not jail  

play24:33

interface of the collection interface now what map  is contains what are the different interfaces and  

play24:39

classes we have let us see so when we need to  go for the map so map is another interface we  

play24:44

have so when we need to go for the map so map is  also by using map also we can represent a group of  

play24:51

elements or group of objects but those objects  will be in the form of key and a value pair  

play24:58

so for example i have a data something like this  right say i have uh employees let's say emp id 101  

play25:06

i have a david and one zero two i have a smith and  one zero three i have a squat so i have a multiple  

play25:14

ids and i have a multiple names and if i just  look at here this kind of data so here every  

play25:20

element every element is an object so here these  are all objects and the names are also object  

play25:26

in the map we can call them as a keys and these  are all the values so key and value pair means  

play25:33

this combination is called as a key and a value  pair so if you want to store this kind of data we  

play25:40

will go for map interface so in the map interface  we can representing group of objects or elements  

play25:46

in the form of key and value pair and every  key is an object and every value is an object  

play25:53

but here the rule is the keys cannot be duplicated  so for example when i say one zero one i already  

play25:59

inserted i cannot add one more one zero one so  the duplicates are not allowed in case of keys  

play26:05

but the values can be duplicated so if i add  david here the david can be repeated once again so  

play26:12

in the map the data will be maintained  in the form of key and value pairs and  

play26:17

each key is an object each value is  an object and keys are unique so keys  

play26:24

we cannot duplicate duplicates are not allowed as  a keys but values can be duplicated so this is a  

play26:31

this is a way we can use map interface so map  interface will be preferred if you want to store  

play26:37

the objects in the form of key and the value  pair and what are other classes are available  

play26:43

which have implemented this map interface now  we will discuss them so map interface is also  

play26:50

implemented by using different classes so the  map interface is implemented so map interface is  

play26:58

implemented by using hash map so this is a  class and which is also implemented by using  

play27:05

linked hash map okay so linked hash map linked  so these are the two classes which you have  

play27:15

implemented this map interface okay so map  is a completely different interface which is  

play27:21

also comes under collection framework but this is  nowhere related to collection so collection is a  

play27:26

parent class and a map is a different class  okay so this is how we need to understand all  

play27:33

the interfaces and the classes from the collection  framework so from the next video i will show you  

play27:40

how we can work with the different interfaces  and different classes all right so that's all

Rate This

5.0 / 5 (0 votes)

الوسوم ذات الصلة
JavaCollection FrameworkData StructuresProgrammingInterfacesClassesListSetQueueMap
هل تحتاج إلى تلخيص باللغة الإنجليزية؟