How to implement iterator as an attribute of a class in Java

后端 未结 6 944
既然无缘
既然无缘 2020-12-17 04:19

let\'s say I have this simple MyArray class, with two simple methods: add, delete and an iterator. In the main method we can see how it is supposed to be used:



        
6条回答
  •  借酒劲吻你
    2020-12-17 04:56

    MyArray should implement the Iterator as it is also responsible for maintaining the array. Simple encapsulation principle.

提交回复
热议问题