Java Programming: Lesson 28 - ArrayLists of Objects

Опубликовано: 13 Ноябрь 2024
на канале: youmils03
84
2

PLEASE SUBSCRIBE!!!

In the previous video (   • Java Programming: Lesson 27 - Intro t...  ), we introduced the concept of an ArrayList. Here, we review the methods discussed previously, explore 4 more, and connect this discussion back to our exploration of object-oriented programming. This requires us to create an ArrayList of Person objects, which we do at the end.

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

0:56 Review of ArrayList Methods (3:52 remember to import java.util.ArrayList!)
4:07 Review of words.isEmpty( ) and words.size( ) [isEmpty returns true if the list has zero elements and false otherwise, and size returns the number of elements in the list]
4:32 Review of words.add( x ) adds element x to the end of the list (recall that words.add(x, y) adds element y to index position x and shifts all subsequent elements one position to the right)
5:36 Review of Iterating through an ArrayList (use for-each loop or get(x) as discussed at 7:06)
6:42 Review of words.clear( ) removes all elements from words
7:06 Review of words.get( x ) returns the element at index position x
7:44 Review of words.contains( x ) returns true if x exists in words, false otherwise
9:19 NEW: words.indexOf( x ) returns the index position of the first occurrence of x (or -1)
10:21 NEW: words.lastIndexOf( x ) returns the index position of the last occurrence of x (or -1)
11:37 NEW: words.set( x , y ) assigns index position x to object y
12:57 NEW: words.remove( x ) removes the element at index position x
14:11 NEW: ArrayLists of Objects

Python has a list data structure which is very similar to an ArrayList. Check out the Python equivalent here:    • Python Programming: Lesson 9 - More L...  

Ready for Javadocs, formal Java documentation? You're making great progress in object-oriented concepts:    • Java Programming: Lesson 29 - Javadocs  

Thanks for watching, and PLEASE SUBSCRIBE!!!