Track Class & Iterator

Music Organization 5

 

External Method Call & Methods in ArrayList Class

Screen Shot 2017-04-19 at 6.00.11 PM.png

Since we import a the Arraylist library class, we can use all the methods within this class, including get(), remove(), contains(), equals(), etc. See more at:

http://docs.oracle.com/javase/8/docs/api/

Screen Shot 2017-04-19 at 6.10.37 PM.png

track.getArtist() use the method in track class called getArtist(). An artist’s name is fetched. Then the system will judge whether this name contains the String that user input.

4.40

4.40.png

4.41

4.41.png

Library V1

get(index) & remove(index)

Screen Shot 2017-04-19 at 6.42.14 PM.png

if(textbook.get(index).getBookName().contains(booktoremove))

In this sentence, firstly we get a book object with a particular index from the textbook Arraylist. Then we get the name of that book object by using getBookName(). Then we check whether the book name contains characters in booktoremove.

Comparison between For, While, and Iterator Loop

Screen Shot 2017-04-19 at 6.46.53 PMScreen Shot 2017-04-19 at 6.46.59 PMScreen Shot 2017-04-19 at 6.47.07 PM

We use for loop when we want to process the whole collection. We use while loop when we want to process a part of the collection. hasNext() is a method from Iterator Class. We need to import java.util.Iterator to use it. Please look at the comments (//) in the screenshots above for better understanding.

Null

The Java reserved word null is used to mean “no object” when an object variable is not currently referring to a particular object. A field that has not explicitly been initialized will contain the value null by default.


Personal Reflection

I learned ArrayList class, Iterator class, three types of loop (for, while, iterator), and null in Chapter four. And I reviewed the Scanner class. I really suffered from recalling syntax since I had stopped programming for a while. So that I should never stop practicing programming, otherwise I have to recall syntax again.


 

留下评论