This video provides a solution to the challenge of creating a grocery list using the ArrayList data structure.
- [Instructor] Welcome back!…How did you make out with the challenge?…I hope you had a good time trying…to create your grocery list.…I'd like to walk through my solution to this problem,…but remember, everybody programs a little differently.…Alright, let's start in the main method.…I'm going to go ahead and create an ArrayList.…Now, I know I'm going to add grocery items,…which I can go ahead and store as strings.…So I'm going to put a data type of string,…and I'm going to give my list a name.…I'm going to call it groceries.…
And that's equal to a new ArrayList,…and I'm going to use the Arrays.asList command…to allow me to just make a list of items.…So, let's do milk,…and then let's do bread,…and let's add cheese to our list.…Okay, that's our first list.…Now, let's add a second list.…Again, it's going to be a type string,…and I'm going to call this one, groceries2,…and that's equal to a new ArrayList.…
Again, I'll do Arrays.asList,…and this time, I'm going to add some baking items.…I need sugar.…I need flour,…and I need baking soda.…
In this course, explore data structures in the Java language. Follow Peggy Fisher as she introduces you to several types of commonly-used data structures in Java. Peggy explores ArrayLists and LinkedLists, both of which implement the List interface, which extends the Collection interface and allows you to access list elements in a specific order. She also goes into the Vector, Stack, and Queue collection classes. To help you better understand these new concepts, Peggy wraps up the course with a challenge—creating a grocery list—and provides a solution for that challenge.
- Reviewing the types of data structures
- Working with the Collection interface and Iterable interface
- Working with ArrayLists and LinkedLists
- Using the Vector, Stack, and Queue collection classes