• 10 minutes ago
Transcript
00:00The next operation we are going to study is the size of an ArrayList
00:03In the ArrayList, we have a length of the ArrayList
00:09In the ArrayList, we have a size function
00:11which is the size of the ArrayList
00:15Let's write code
00:16If I have made a list of integer type in my main function
00:20and I have added 5 integers
00:22What am I going to do now?
00:24I am going to print list.size
00:27In println, I have written list.size
00:31and this is the size
00:32such as a property in the ArrayList
00:35This is not a property, it is a method, it is a function
00:39Let's print size
00:40I will do this
00:42Save and run
00:44I will print 5
00:46My list has counted all the elements
00:48Now, I can also iterate on the ArrayList
00:52In the ArrayList, I used a whole loop
00:56I was going to create a loop
00:56I is equal to 0, I is less than length, I is less than length, I is less than length
00:59I is less than length, I is less than length, I can also do the same thing
01:02If I have to print the ArrayList
01:04How will I print the ArrayList?
01:06I can print a loop
01:08For int i is equal to 0
01:10I is less than list.size
01:14Here, I usually have the Array.length
01:16Now, I have the list.size
01:18And I will do this
01:19I++
01:21And now, I have to remove the ArrayList
01:24I will print the ArrayList
01:24So, I will print list.get
01:27I
01:28Because the get function is used to get values
01:31Here, I have two methods used in my list class
01:34One, I have used size
01:36For the object size
01:37One, I have used get
01:39For the i-th index
01:40For the stored value
01:42Here, I will put another print element
01:45Let's do this
01:45Save
01:48Now, run
01:49So, what happened?
01:50First, I have 5 printed which is my size
01:53After that, all the elements are printed
01:55Meaning, 1, 2, 3, 4, 5
01:56Here, I will give a little gap of space
02:00And then run
02:02Then, I will have the ArrayList
02:04In this way, I have the elements in my ArrayList
02:06So, if I have to iterate on ArrayList
02:09Or add a loop
02:10Then, I will use what I will use
02:11I will use my ArrayList.size
02:13So, let's go