PLEASE SUBSCRIBE!!!
In the previous two lessons ( • Java Programming: Lesson 48 - Threading and • Java Programming: Lesson 50 - LinkedList M... ), we learned about LinkedLists, which are better than ArrayLists at inserting and removing elements but worse than ArrayLists at accessing and modifying elements. For either list, we can sort, find the minimum, or find the maximum element using particular static methods from the Collections class, after importing it at the top of the file. Furthermore, an iterator is an object that allows us to parse the elements of an ArrayList or LinkedList. Both the Collections class and iterator will be discussed for at least 5 minutes in the next video.
Collections.sort( list ); //sorts an ArrayList or LinkedLists of objects according to the compareTo( ) method of the class
Collections.min( list ); //returns the minimum element in the ArrayList or LinkedList according to compareTo( )
Collections.max( list ); //returns the maximum element in the ArrayList or LinkedList according to compareTo( )
Use myList.iterator( ) to create an iterator which iterates through an ArrayList or LinkedList called myList
while( listParse.hasNext( ) ) //checks if there's another element to iterate through in the list
{
Q myObject = listParse.next( ); //goes to the next element in the list
//doSomethingWithMyObject
listParse.remove( ); //removes myObject from the list. Optional operation (not always used)
}
0:02 Review of LinkedLists
7:53 NEW: Collections.sort( list )
13:18 NEW: Collections.min(list) and Collections.max(list)
15:37 NEW: Iterators
The Python connection to a topic on iterators is provided in this video: • Python Programming: Lesson 62 - Iterators ...
Ready for another type of data structure? Check out stacks here: • Java Programming: Lesson 52 - Stacks
Thanks for watching, and PLEASE SUBSCRIBE!!!
On this page of the site you can watch the video online Java Programming: Lesson 51 - The Collections Class and Iterators with a duration of hours minute second in good quality, which was uploaded by the user youmils03 29 September 2021, share the link with friends and acquaintances, this video has already been watched 48 times on youtube and it was liked by 0 viewers. Enjoy your viewing!