When should I accept a parameter of Iterable vs. Collection in Java?

后端 未结 9 1623
独厮守ぢ
独厮守ぢ 2021-01-30 01:06

What are the considerations of using Iterable vs. Collection in Java?

For example, consider implementing a type that is primarily concerned with contai

9条回答
  •  南方客
    南方客 (楼主)
    2021-01-30 01:26

    See "Why so much emphasis on Iterators and Iterables?" on the Google Collection FAQ for a decent argument for preferring Iterators, especially when dealing with a lot of data. One analogy that might help is to think the difference between forward-only read-only cursors and scrollable cursors.

提交回复
热议问题