• 2 days ago
Transcript
00:00Hi everyone and in this chapter we are going to talk about ArrayList
00:03Now ArrayList is a new data structure which we are studying today
00:06Let's talk about ArrayList in Java
00:08This is an inbuilt data structure
00:11Inbuilt, this is the first data structure
00:14We have to implement all the operations that we have made before
00:18We have to implement all these operations
00:20According to our use case
00:22And secondly, this data structure is a linear type
00:25Linear means data which is stored in a linear fashion
00:31When we studied ArrayList
00:34We used to visualize the ArrayList
00:39We will call it a linear structure
00:41Why?
00:42Because my data is stored in a straight line
00:43In that way, my ArrayList is also a linear structure
00:50Let's talk about ArrayList actually
00:52What is happening?
00:53If I compare Arrays with ArrayList
00:56Then we talk about Arrays' properties
00:59The first property that comes in our mind
01:02It comes to Arrays' fixed size
01:05It comes to Arrays' fixed size
01:06Fixed size
01:06If I have defined an array in the beginning
01:09I can increase the size of ArrayList
01:10Then I can increase the size of ArrayList
01:12I can increase the size of ArrayList
01:14If I have written this line
01:15Int a is equal to new int of 5
01:21Then in this array, in this array
01:24In this array, in this array
01:25In this array,
01:28In this array,
01:29In this array,
01:29In this array,
01:29In this array,
01:30In this array,
01:31If I have tried to store it in this array
01:32Then the array is an exception
01:38Out of bounds
01:40Out of bounds
01:40Out of bounds
01:41You have defined the size
01:42You have tried to store it
01:45But the array is fixed size
01:48But imagine a case where I store a role number of students in an array
01:53Now in my class, there are 30 or 5 children in my class
01:57So what will I do? I will make an array of 5 size
02:00Let's say that in my class, there are 5 students in my class
02:02And I have made an array of data for 5 students
02:05I have named this array
02:08So I store all the students' role number in this integer array
02:12Here students are 0, 1, 2, 3, 4
02:16So once I store a role number here
02:18And what happens after 2 months
02:20After 2 months, I have another student
02:24Now I can't fit in this array
02:27Because I have completely filled this array
02:31So I have defined the size of my array
02:35It will not increase
02:36If I store this new data
02:39What will I do?
02:40I will make a new array
02:41Which will increase the size
02:44And in that I will store my new student's data
02:47But if there is another new student
02:50Or two new students
02:52Then in this way, we need a modification mechanism
02:55In the array
02:56In which we can implement the real-life cases
03:00So this mechanism
03:02Comes with a dynamic size
03:05So in the array
03:07And with the fixed size
03:08The constraints
03:09That we are holding
03:12ArrayList
03:12Solved
03:13ArrayList
03:14ArrayList is a data structure
03:15Which is dynamic
03:16The size
03:17Dynamic
03:18Which is
03:19Which can be
03:20Which can be
03:20Which can be
03:21Which can be
03:21Which can be
03:22Which can be
03:23Which can be
03:23Which can be
03:27Which can be
03:27Which can be
03:28Which can be
03:30In the arrayList
03:31So this
03:32Inbuilt
03:33That is
03:33That Java has already
03:34Built for you
03:35We have to use it
03:36As a property
03:38That it is dynamic size
03:40In the arrayList
03:41We are learning
03:42How to implement
03:42ArrayList
03:43How to implement
03:44ArrayList
03:45Now we are learning
03:45To use Java
03:47ArrayList
03:47So first
03:49Differentiation
03:50Arrays
03:50ArrayList
03:52Arrays
03:52Arrays
03:56ArrayList
03:58We can store
03:59Primitive Data Types
04:01Primitive Data Types
04:01Primitive Data Types
04:03Primitive Data Types
04:04Int
04:04I have written
04:05Int
04:06My Primitive Data Types
04:08We have done
04:09In the first class
04:09In the first lecture
04:11Car
04:14Boolean
04:15Float
04:16These are all
04:17My Primitive Data Types
04:18If I want to make
04:20ArrayList
04:21I can make
04:21Primitive Data Types
04:23Or Non-Primitive Data Types
04:24But ArrayList
04:26ArrayList
04:26Which is in Java
04:27It is only
04:28Non-Primitive Data Types
04:30We cannot store
04:31Primitive Data Types
04:32We cannot store
04:32ArrayList
04:34In the first lecture
04:35So if I have
04:36ArrayList
04:37I can store
04:38Int
04:38Type
04:38Data
04:39I can store
04:41Int
04:42Integer
04:44Integer
04:44Integer
04:46Integer
04:47Integer
04:47Integer
04:47Integer
04:53Integer
04:54Integer
04:56In Java
04:56In JavaTION
04:57Then
04:58This
04:58is my main function To
05:02save But
05:04I
05:05need to import which
05:06one package
05:07In
05:09Java
05:10Utah
05:17ErrayList
05:18all the properties we can use.
05:21Besides, if we have written this
05:22java.util.star
05:25then this is also right.
05:27.star means in Java
05:28everything.
05:29Besides the other classes,
05:32interfaces etc,
05:34all the .star will come with us.
05:37But since we have only
05:38used ArrayList, I am just
05:40writing ArrayList.
05:41By writing this statement,
05:43we have ArrayList class
05:46in Java.
05:47We will use it in our classroom class.
05:51In the main function,
05:52I want to make ArrayList.
05:53What do we do? ArrayList of Integers.
05:57It is a data structure
05:58that will store integers.
06:00Because ArrayList is fixed size
06:02and ArrayList is not.
06:03I can make ArrayList without size.
06:06The syntax of ArrayList
06:08is that we will write ArrayList.
06:10After that, we will write
06:12Angular Bracket.
06:13After that, I will write the type
06:14which I want to store in this ArrayList
06:15which I want to store in this ArrayList.
06:17Then I want to store integers.
06:20What do I want to write?
06:21Then I will write here,
06:22I will write my ArrayList's name.
06:25Here I will write integer.
06:28But if I want to store a string type
06:29I want to store this.
06:32If I want to do Boolean type,
06:34I will write Boolean class.
06:37Boolean class starts with B.
06:38In Java, the name of ByConvention
06:41is the name of ByConvention.
06:43The name of ByConvention is the upper case.
06:44This is ArrayList's AB capital.
06:46Classroom's CB capital.
06:47String's SB capital.
06:49Boolean's BB capital.
06:50So remember,
06:51when we create a class,
06:53we will write the name of capital.
06:56If we put small,
06:57then we will run code.
06:58But capital is used by convention.
07:00Now I can store float type data.
07:04So I will write float class.
07:05So whatever data I want to store,
07:07I will write class.
07:09Then I will write my ArrayList's name.
07:11And I will write is equal to new ArrayList.
07:15Then angular brackets,
07:17parenthesis,
07:18and last statement terminator.
07:20Now the syntax is very similar.
07:22The syntax that we have taught in Oops class
07:24is how to define an object.
07:26What did we write?
07:27We wrote our class.
07:29Then we wrote our object.
07:33We wrote it equal to new.
07:36We have put our object in our heap memory.
07:39Then we wrote class again.
07:42We called our constructor.
07:45So the same syntax is following here.
07:47How is it?
07:48ArrayList is my class.
07:49This list is my object.
07:51I have made the area list in memory heap.
07:54In my class again.
07:56And here I have called my constructor.
08:00Now what are these angular brackets?
08:02These angular brackets mean that you want to store
08:04what kind of data you want to store in this area list.
08:07Just for that purpose,
08:08the angular brackets are here.
08:09So we can show the type of data.
08:12So once I have made this list,
08:13I have made the integer variables.
08:17If I want to store the string,
08:19then I will write here.
08:21I can name it.
08:22List2 is equal to new.
08:25ArrayList.
08:28If I want to store Boolean,
08:30then I can write
08:30ArrayList of Boolean.
08:34List3 is equal to new ArrayList.
08:37So in this way,
08:39I define ArrayList in Java.
08:41Now,
08:42students who have studied C++
08:43or their background is C++
08:45in a little bit in school.
08:46So in C++,
08:48there is a thing called vectors.
08:50What are vectors?
08:51What are vectors?
08:51Vectors are also variable size.
08:53And like the work of vectors
08:54in C++,
08:56that is the work in Java.
08:58So it is the same.
09:00And ArrayList is part of something called
09:02Java Collection Framework.
09:06In Java Collection Framework,
09:08we will study in detail
09:09and this is the word
09:10in the next classes,
09:12in which we are going to study
09:12some data structures.
09:14In it, we will get to listen
09:15and listen to it.
09:16And we will talk about it
09:17in detail.
09:18The Collection Framework
09:20is basically
09:20in Java,
09:21some classes,
09:22some interfaces
09:23are collected
09:24which we can use
09:26a lot of data structures
09:27and inbuilt data structures.
09:29There are many data structures
09:31that we don't have to create
09:32from scratch
09:33when we are in coding test
09:34or in interview.
09:36We will get inbuilt
09:37in Java.
09:38So we are talking about
09:40In fact,
09:41if I see here,
09:42I don't have to create
09:42the ArrayList
09:43I don't have to create
09:45the variable size
09:46or the fixed size
09:47or the property
09:48I don't have to implement
09:49or code.
09:50What is it?
09:51Java already exists.
09:53That is why
09:54I can say that
09:55the ArrayList
09:55is the Java Collection Framework
09:58in Java.
09:58We will talk about it
10:00in detail.
10:00We will talk about it
10:01There is a lot of syntax
10:02in Java
10:03to define an ArrayList
10:05in Java.
10:05It is not possible.
10:05in Java.
10:05So...
10:05in Java
10:06It is a lot of