Collection Interface vs arrays

后端 未结 5 507
庸人自扰
庸人自扰 2020-11-29 02:02

We are learning about the Collection Interface and I was wondering if you all have any good advice for it\'s general use? What can you do with an Collection that you cannot

5条回答
  •  迷失自我
    2020-11-29 02:41

    One advantage is the Iterator interface. That is all Collections implement an Iterator. An Iterator is an object that knows how to iterate over the given collection and present the programmer with a uniformed interface regardless of the underlying implementation. That is, a linked list is traversed differently from a binary tree, but the iterator hides these differences from the programmer making it easier for the programmer to use one or the other collection.

    This also leads to the ability to use various implementations of Collections interchangeably if the client code targets the Collection interface iteself.

提交回复
热议问题