PLEASE SUBSCRIBE!!!
In the previous lesson ( • Java Programming: Lesson 26 - Integer... ), we learned about wrapper classes. The Integer, Double, Boolean, and Character classes wrap primitive data types into objects, providing additional functionality like methods and constants that would not be supplied by a primitive int or char.
This video introduces ArrayLists, a powerful new data structure. It is also known as a dynamic array, equivalent to a list in Python. This is essential for storing our objects in a list that can change size. Here, we learn how to determine whether a list is empty, its size, add elements, retrieve elements, clear elements, and contains an element.
1. import java.util.ArrayList; before your class
2. create an instance of the ArrayList class using angled brackets to contain the object type (YouTube won't let me show that symbol)
3. google ArrayList Java API
4. call methods from the API on your ArrayList and play around with different operations
1:34 NEW: Understanding and Importing the ArrayList Class in Java
3:24 NEW: Creating an ArrayList Instance
4:24 NEW: ArrayList Methods
6:58 NEW: words.isEmpty( ) returns true if words has no elements, false otherwise
7:51 NEW: words.size( ) returns the number of elements in words
8:09 NEW: words.add( x ) adds element x to the end of the list
9:11 NEW: Iterating through an ArrayList
10:05 NEW: words.get( x ) returns the element at index position x
11:32 NEW: words.add( x , y ) adds element y to index position x and shifts all subsequent elements one index position to the right (adds 1 to them)
14:00 NEW: words.clear( ) removes all elements from the list
15:08 NEW: ArrayList Elements must be Objects
16:18 NEW: words.contains( x ) returns true if x exists in words, false otherwise
Python has a list data structure which is a little easier to use than a Java ArrayList, but awfully similar! Check it out: • Python Programming: Lesson 8 - Introd...
More ArrayList methods with a connection back to OOP fundamentals can be found in the next video: • Java Programming: Lesson 28 - ArrayLi... (Lesson 28)
Thanks for watching, and PLEASE SUBSCRIBE!!!