‫Narrator: Hi.
‫Inside of this lecture we're going
‫to learn something called array list.
‫Working with arrays is cool actually.
‫Okay, I'm going to name these arrays
‫and how even cooler data structure called
‫the array lists.
‫So sometimes you see as lists
‫in other programming languages.
‫In Java, we call them array lists
‫but they're basically the same.
‫It's actually the same thing with arrays
‫but it's much more flexible
‫when we compare it to the arrays,
‫because over here when you initialize
‫a new empty array
‫you have to specify some kind of perimeter
‫that limits the capacity of those arrays.
‫But inside of an array list,
‫you don't have to do that at all.
‫You can just initialize an array list
‫as an empty list and you can add
‫or just remove any element
‫that you may want later on.
‫For example, you can just write array list
‫and beware, there is some kind of
‫angler parenthesis over here
‫which is smaller or bigger size,
‫and over here you have to specify the type
‫of the variable that you're going to be storing
‫and those array lists.
‫So I'm going to call string for example,
‫because they will be a string.
‫It's going to be a string array list.
‫I'm going to call this my musicians,
‫okay?
‫And I can come over here and just say
‫this is going to be a new array list
‫and close the semicolon.
‫So maybe you can come up
‫with situations like that
‫where you will see the type
‫in the second right side of the equation as well.
‫Like new array list string over here.
‫You don't have to do that actually, it's deductible
‫but if you see it like this,
‫yeah, it's okay as well.
‫Okay.
‫You have to be
‫using this before
‫but right now it's perfectly okay.
‫So my musicians dot add,
‫will add a new element to the array list.
‫So it'll expect string,
‫obviously, because we made it to be.
‫Now I can just say out that print line
‫my musicians dot get.
‫And when you say dot get,
‫it will ask you for an integer
‫which is an index.
‫Okay? So,
‫I'm going to say zero because we are already
‫have only one over here.
‫It will bring out to James to me like this.
‫So I can add as many as I want.
‫Like I said,
‫I can say my musicians dot add Lars,
‫and I can come over here and say my musicians dot add
‫and actually I can add it anywhere I want as well.
‫It has some different values, different properties
‫different methods like this.
‫As you can see,
‫you can just specify the string
‫but you can specify the index
‫if you want as well.
‫For example, you can say that,
‫yeah, add large but add it to this index.
‫Okay? I don't want it to be added
‫on the last index that you're available.
‫I want Kirk on the first index
‫which is the second element of this array list.
‫So it will be James, Kirk and Lars
‫in this case, right?
‫So let me do it like this.
‫I'm going to add another one called Rob and
‫let me just
‫get everything in this list
‫so that you can see what's going on,
‫rather than zero,
‫I'm gonna say one, two, and three.
‫And later on, don't worry.
‫We are going to see a perfect way
‫to get every element inside of an array list
‫with a single method.
‫So here you go, James, Kirk, Lars, and Rob.
‫If we hadn't had this index thing
‫then we would have seen James, Lars, Kirk, and Rob,
‫but this time we see James, Kirk, Lars, and Rob
‫because we specified Kirk
‫to be put into the first index
‫as the second element inside of this array list.
‫So that's how you work with array lists.
‫As you can see it,
‫it's much more flexible when we compare them to the arrays.
‫You can just not specify any kind of capacity at all.
‫You can put the elements
‫in whatever index you want
‫and it's perfect for working with data
‫that you are not sure of.
‫Maybe you're downloading it from internet
‫and you don't know whether it's going to be ten elements
‫or 12 elements or 1000 elements.
‫So you're gonna come across array list
‫in the Android applications very often.