Java Collections Framework-Part1 | Collection Vs Collection Framework

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome you all this is pawan from hdt channel so from today onwards we are going to see java collections framework so as part of today's session we'll see some detection part like what is collection and what is collection framework and what are the different collection types are available in java right so first of all let us start with what is collection so what is a collection so first let us try to understand this term what is collection so this is basic general term which you can use commonly like group of objects is a collection so for example let us say i have multiple students in the class it's a student 1 and student 2 and student 3 so all together we can call as a collection of students and similarly when i take an organization we have a multiple employees let's say employee one employee two and employee three and so on so all of them comes under one collection so collection of employees similarly collection of pins or collection of animals so we can use this collection term in general so that representing a group of objects so that is simple definition what is meant by collection so collection is a group of objects and the collection is representing it is a single entity which is representing multiple objects collection is a single entity which is representing multiple objects but what about the collection framework so in java uh to represent group of objects into a single entity we need certain number of classes and interfaces so collection framework which will provide you those classes and interfaces so what is collection framework means it defines the different interfaces and classes by which we can represent group of objects into a collection so that is a basic difference between collection and collection framework so let me just repeat once again with some examples so what is a collection and collection framework so for example let us say a collection so i have a student one and i have another student two and i have another student three so i have a three students so collectively i will call as a one collection collectively i have called as a one collection so to representing this collection or to representing a group of element we need a collection so how we can represent a group of element into single entity we need a special classes or interface so for example in java so we have something called arraylist so when i say arraylist equal to new arraylist when i create an object like this i can store a group of elements into error list so this is a one example of the collection framework so the collection framework is a group of classes and interfaces by which we can represent a group of objects into single entity so that is the basic difference between collection and collection framework so before discussing the collection framework first of all we need to know why we need to go for collection framework why we need to have a collection framework in java so to understand this better let us see one example suppose in java so if you want to uh store a value into a variable so first we will define like this so first we will have some data type and then we define some variable name let's say a and here i'll say something called 10 so what exactly this is representing int is a data type and a is a variable 10 is a value and similarly if i want to store one more value into a variable so again i have to define one more variable and then i can store some other value similarly if you want to store 100 numbers like this so 100 variables we have to create so to store 100 variables we have to create to store 100 values we need to create 100 variables so this is a not a best programming practice so it is not a best programming practice so what we have to do is to representing many numbers so here let us conserve this each and every value is one object to representing these all the values we will create a one variable let us say i will create one small variable by using array so when x for example let us say integer a and equal to new int and here i'll say 100 so when i create an array variable like this in java so there is a single variable which can hold multiple values that means it can hold group of elements or group of objects so here every element so for example if i create 100 like this which will create 100 memory locations like this let us say here starting from 0 index is starting from 0 1 2 3 so 100 locations it will be created so in each and every location we can put some value or sometimes we can also store object elements so we can use this array which will representing or which can store multiple elements or multiple objects so is it it is clear till here because the collection is nothing but to representing the group of elements as a single entity which is a collection so if i just look at this example so we can achieve this somehow by using array concept because here if i if i specify the size here so you can store some group of elements into a single variable so if you if you have some value here 10 if you want to access this value so we can say a of zero so by using this index number i can access the values from this array so if you just look at this example in array concept we have certain limitations so what are those limitations we have in this area so now we will discuss this because to overcome those limitations corrections framework framework come into picture so what are the problems with the arrays concept so let us see here i created one array let's say int a and equal to new end of here i can say some size let us say i put some 10 so when i say 10 here which will create 10 different locations and array will be created like this and 10 rows will be created index will start from 0 so 0 1 2 and the last index will be 9 because the index will start from 0 so the last index will be n minus 1 always so it is 9 here so we can store different elements here 10 or 20 30 40 and so on so this is normal array concept so in this array concept what is the problem with this is when i create an array like this in the array we can store homogeneous data only so what is homogeneous data means we can store only same group of elements so same kind of elements so that means if array is defined with the integer type i can store only numbers in that suppose if i create this array with double or string type i can store only string on that so that means array will allow us to store only homogeneous data so homogeneous data in the sense the same kind of data similarly if i create a array with a student class object let us say here student stu and equal to new student of i'll say 10 now observe this instead of data type i use some class here student so when i create array like this student sto is an array and new student of 10 so in this particular array so which will create 10 locations right which will create a 10 location let's say 0 1 2 and so on so in every location we can we can store some student object details like here one object we can store and here one object another object we can store or here we can store another object so again here if you just look at here when i create an array with the student type i can store only student information in those locations it can hold only student objects but here when i create a student stu and here i'll say new i'll say customer so this is a different class so this cannot hold now because the array can hold only homogeneous data so homogeneous data means the all the data elements should be the same type so we cannot store multiple data elements in the array so this is a one limitation we have this in array but still we can overcome this limitation by creating object array so instead of creating the into or instead of for specifying the student specifically if i create an object array which can hold everything so for example let me create an object let me create array with the object type so this is called object array so now a is created let's say new [Music] so let me just say like this this is an object array so new object now observe this so here i'll say 5 so now i created an object array so when i create an object array i can store homogeneous data as well as heterogeneous data that means it can hold same data type elements and i can also store multiple data type of elements so for example so it will create multiple locations five locations and here i can put number or here i can put decimal number or you can here i can put a string and so on similarly a different type of objects also we can store in this array so somehow we can achieve this we can overcome this problem by using object array so here also we are representing group of objects into a single entity so group of objects into a single entity so this is also a kind of a collection now we'll see the what is the problem with this array so based on this problem we can overcome this problem by using collections concept so when i take this array concept so the first problem with this is the first problem with the array is the array is having a limited size so for example when i say 5 that value is a fixed so i cannot store more than 5 values so array is fixed in size so at the runtime i cannot increase or decrease the size so five is a fixed size so when i define the array that the size is fixed so it will create five elements so it can create five store five memory locations and i can store only five elements into this array and if you are trying to store one more element it will throw an exception like error index out of one exception so that is a problem suppose if i created five elements in the array five memory locations i created and if i store only three elements when i store only three elements and rest of the spaces will be wasted so this is a one problem with the array so array size is always fixed so at the runtime we cannot increase or decrease the size and suppose if we want to store more than these elements still there is a problem and if i store less number of elements still the memory will be wasted so this is the one problem with the array and the second problem is the second problem is so what does that mean is array is a fixed in size means it is not growable so these are technical terms like arrays are not growable in nature so that means at the run time we cannot increase or we cannot decrease the size of an array so that is that means array is a not growable in nature it is not growable in nature this is a first problem so the second problem with the array is size is fixed and second problem is we can store only same data type of element that means homogeneous data okay only homogeneous data we can store in this area only homogeneous data that means same data type of elements we can store in this array there's a second problem and we already seen sizes fixed because at the runtime we cannot increase and we cannot decrease the size and they are not growable in nature so these are the two problems the third problem is so while implementing the arrays they have not basically used any data structure underlying data structure concept so while implementing the arrays in java they are not basically using an underlying data structure concept so we cannot it cannot support any ready-made methods we can say ready-made methods what is ready-made methods means suppose when i create an array right if i want to sort some elements or if you want to set some element is there in the array or not i need to write a logic for that i don't have any predefined methods for that okay so because the arrays have implemented no arrays are not implemented by using any underlying data structure so that is a problem so the reading ready-made methods are not there in the arrays so this is one more problem so arrays are in fixed in size and error arrays hold only homogeneous data and arrays are not implemented by using any data underlying data structure so we don't have ready-made methods we cannot use those methods and if you want to do any operations on the arrays we have to write a programming logic so this is a these are the basic problems with the normal arrays concept so to overcome these problems to overcome these problems we have collections available in java so collections framework so now we will discuss why we need a collection so in the normal arrays concept we have these problems so we have in fixed size we can store only homogeneous data and they don't have any underlying data structure so we cannot use any ready-made methods so when you come to the collection framework so collection framework so java in the collection framework they have provided certain number of classes interfaces so we have something called arraylist and we have something called list is also an interface which is realistic derived from the list and we have something called hash map and we have something called okay so hash table and we have something called tree stack and so on so there are so many classes and interfaces are available so by using all these types right we can maintain the we can store a group of elements into a single entity so what are the additional advantages we will get when you use the collection types over arrays concept so far we have seen arrays concept how we can store multiple data type of elements and also we have seen what are the limitations we have in this array right so now i will show you how we can overcome those problems by using this collection types so let us try to compare arrays and collection so why we need to go for arrays because in arrays we have some limitations to overcome those limitations we go for collection concept so well let us compare with erase and collection array and collections so collection in the sense it can be any collection like it can be array list hash map vector tree whatever linker list everything all that comes under the collections now what are the basic differences between collections and errors concept so we have noticed we have some limitations in array so what what is the first limitation is a fixed size so if you want to create an array before that we need to know how many elements we are going to store in this array and then we can create an array we can proceed further so the size is fixed at the runtime if you want to add a new values or if you want to remove the existing values it is not possible in this areas concept okay so we have to write a programming logic so fixed size so the runtime we cannot increase or decrease the size and if you want to store more than more elements than the size it will throw an exception similarly if you want to store a less number of elements based on the size suppose if i say size is 10 if i store only 5 elements still the rest of the memory will be wasted so basically areas are not growable in nature but whereas in collection they are growable in nature growable in nature so what does it mean is at the runtime if you want to add a new elements we can still keep on adding a new data elements and similarly if you want to reduce the elements if you want to remove the elements at the random we can remove the element so because of the removing there is no memory wasted will be there so collections are growable in nature whereas arrays are not growable so that is fixed size there is a first difference and now come to the second difference is arrays can hold homogeneous data it is can hold homogeneous homogeneous data when you come to the collections it can hold homogeneous data homogeneous data plus heterogeneous data heterogeneous in the data means it is can have all kinds of data elements so different data type of elements can store so that is an one more advantage of collection framework so homogeneous data plus heterogeneous data also can be stored in the collection so there's a second one so third difference is in the normal arrays concept so because arrays are not implemented based on by using any data structure underlying data structure so ready-made methods are not there so if i create an array if you want to search an element if you want to sort an elements we have to write a programming logic okay so that means there is no underlying structure so there is no underlaying underlying data structures so there is no ready-made methods available so ready-made methods not available if you want to do any operations on java we have to write a programming logic for that but when you come to the collections the collections are implemented by using some data structure underlying data structure so so it is implemented by using data structure underlying data structure so that means the ready-made methods are available so ready-made methods are available so what is ready-made methods means for example if i create a normal array right so if you want to sort or if you want to search in elements in this array we have to write a programming logic for that so instead of a when i create an error list right so when i create an error list basically what is an error list real list is a collection so when i create an error list so we don't need to write a such logic for that so we have a ready methods or this or sort or search so we have a ready-made methods are there so by using those ready-made methods we can do different operations on the collection so that means so there is no underlying data structure for the arrays concept whereas in the collection all types of collections are implemented by using some underlying data structures so that's the reason the ready-made methods are available so for every collection there are certain methods are available by using those methods we can perform certain operations on the collections so this is the way we need to understand what exactly collection means and collection framework and what are the different classes and interfaces are available in the collection framework right so this is basically introduction part of the collections and in the coming sessions i will show you we will see how we can learn uh what are the different type of collections how we can work with the array list hash map a tree vector so all types of collections what are the different classes are available what are the different type of interfaces are available so we will see all kinds of things from the collection framework okay so this is the introduction part what exactly collection means collection framework means and what is the difference between collection and correction framework and why we need a collection framework and what are the different collection classes and interfaces are available all right so that's all for this
Info
Channel: SDET- Automation Techie
Views: 44,782
Rating: 4.9523811 out of 5
Keywords: Python, Selenium with Python, Selenium webdriver, Automation, Testing tools, Selenium tutorials, Manual testing, SDET, Java, selenium with java, web services, postman, soapui, rest assured, SQL, Programming, Software Testing material, selenium videos, python videos, automation vidios, jmeter, performance testing, QA, QC, Agile testing, SDLC, Automation Step by Step, restapi, Java Collections, Java collections framework, LinkedList, Set, Collection, ArrayList, HashMap
Id: hKhlkx_6HeI
Channel Id: undefined
Length: 20min 24sec (1224 seconds)
Published: Mon Sep 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.