Hi Catherine, there's actually a limitation about arrays.
>> What do you mean that's what you wanted us to use with wrong with that?
>> Well I've been thinking about it, and there's actually a better data structure
for us to store these words in case we want to add more to the future.
>> What data structures is that?
>> Well it's something called a arrayList and we can use these stackable
boxes as an analogy >> For example,
if we want the arrayList to shrink size, we just remove elements from it, and
if we want to grow, we can just add elements onto it.
>> Okay.
How big does it actually get?
>> Well, there's actually no upper limit to how big the arrayList can get
whereas with the array once we create It's stuck that size.
Okay.
So where do I put these?
Because I want to put the strings one, two, and three and there.
>> Were we first working on the first element.
>> Okay. >> So
you're working down the second element.
>> Okay. >> And the third word we're
going to third element.
>> Okay.
So can I put anything in an element of an array list?
>> Or we can put anything a realist can only whole object out of types.
>> As opposed to.
>> Or remember primitive data types >> Things like integers, bullions,
and floats.
>> But if I want to store an integer in an element?
>> Well it's kind of tricky.
But in Java we have something called object grabbers.
They wrap around primitive data types to help them become object data types.
So, for example, we can store the capital I integer.
But we can't store the lower case i integer.
>> Okay. I got it. So
an array list can hold object data types not primitive types.
It just seems like an array list is a lot more flexible, because
there's no wasted spots as compared to an array which could have blank spots.
So why not just always use an array list?
>> Glad you asked.
So I have this wonderful comparison chart that'll answer all your questions.
>> Okay, let's check it out.
Here's the table that compares and contrasts the Array and the ArrayList.
Like we mentioned earlier, an Array cannot change size once created,
whereas an ArrayList can change size.
Now for the question is it a class, an Array is not a class.
It doesn't have methods to access and modify elements.
On the other hand, an array list has a list of class definition.
This means that every instance of an array list is an object, which has
methods we can use to access and modify the data, and so that's showcase here,
and what each data structure can store is different as well.
And array can contain primitive an object out of types.
However an array list can only contain object out of types.
So to help make this clearer, let's look at some example scenarios and
real Android apps within the settings up.
We have a Wi-Fi screen that shows a list of available Wi-Fi by networks near you.
In this case, we probably want to store this information in an array list, and
this is because the list of available WiFi networks can grow or
shrink depending on where you're located.
Sometimes there are no WiFi networks near you, and other times there might be
a ton, in this case it doesn't make sense to have a fixed size array.
In the YouTube app, there's a feature that can allow you to create a playlist
of videos to watch later.
And this is an ideal situation for
an arrayList, because we'll continue to add videos that we want to see and
remove those the we've already watched, and since we need the data structure to
dynamically change in size we should use an arrayList.
On the other hand, an alarm clock app we have a potential use case for an array.
When you specify an alarm you specify what day of the week
the alarm should repeat on.
This could be a boolean array, which source true if the alarm would happen on
that day and false if the alarm should not happen on that day.
So there are only ever be seven days in a week, so
the size of our boy in array won't need to change over time.
Hence we can use in array.
Another possible use case for an array is the Google Play store App.
When searching for an app you can view a list of categories,
which includes Includes businesses, communication, education apps and more.
If you scroll up and down,
the number of categories in the Play Store will stay pretty fixed over time.
So in this case, will use an array to store this information.
Now to summarize array and array list are two different types of data
structures that are ideal for different use cases.
Arrays have a fixed size, while array lists have variable size.
You can store objects and primitives in an array.
While can only store object types in an array list.
Next we'll dive in and see how to write code to create an array list.