Forum Stats

  • 3,826,744 Users
  • 2,260,702 Discussions
  • 7,897,069 Comments

Discussions

page 7 of slides for lesson 4-3

3462211
3462211 Member Posts: 27
edited May 23, 2017 12:48PM in Java Puzzle Ball

Hello,

I have a few questions regarding the code on page 7 of the slide for lesson 4-3, which I copy-typed at the bottom.

1) Does abstract class Account act as the variable value for Java special class ArrayList?

2) Is accountList an instance of ArrayList?

3) Is stream() a method of accountList?

public class ButtonController {

     ArrayList<Account>  accountList = new ArrayList<>();

...

     public void button3Pressed(){

          accountList.stream()

...

     }

}

Any idea from anyone? 

Thanks,

Carol

3462211

Answers

  • NickR2600-Oracle
    NickR2600-Oracle Member Posts: 530 Employee
    edited May 22, 2017 5:41PM

    Hi Carol,

    1) In this case, accountList is the variable name of the ArrayList instance.  accountList's values are assigned in the NewFXMain class.  To do this, an account is added to the ArrayList, one at a time.  The special <> syntax are called "generics"  They specify the type of objects which may be contained in the ArrayList.  The magic of inheritance and polymorphism lets accountList contain any type of Account, as long as the account is an instance of a class which is inheriting from Account.

    2) Yep!

    3) Yes, stream() is a method which all ArrayLists are capable of.  The ArrayList class actually inherits the method from the Collection interface.  The stream() method is like a getter method.  But instead of returning a number or text, it's returning an object.  This lets you use the dot operator again to call more methods on that stream, like .filter() and .forEach(), just like you'd use the dot operator to call a method on any other object.

    Nick

    34622113462211
  • 3462211
    3462211 Member Posts: 27
    edited May 22, 2017 11:28PM

    Thanks a lot for your explanation Nick.  This is probably just a typo.  Just in case you're interested in knowing it... 

    On page 17 of the slides for lesson 4-2, it stated

    "If you make a mistake and need to change your logic, you can change it in once place (the variable) instead of..."

    Do you actually mean one place?

    Carol

  • NickR2600-Oracle
    NickR2600-Oracle Member Posts: 530 Employee
    edited May 23, 2017 12:48PM

    You're welcome!  Thanks for spotting the typo.  I've updated the slides.

    34622113462211