1.Iterable接口与Collection:由于Collection集合(List、Set、Queue)继承了Iterable接口,因此迭代及foreach适用于任何Collection对象。
迭代器与Collection、Map集合
2.Iterable接口与Map:由于Map接口没有继承Iterable接口,因此Map对象不能直接使用迭代及foreach,但是Map.entrySet()、Map.keySet()、Map.valueSet()返回的是Set,所以迭代可用于Map.entrySet()、Map.keySet()、Map.valueSet()。
迭代器与Collection、Map集合

任何实现了Iterable的类都可用于迭代器及foreach语句中。
从Iterable接口的源码可知,foreach是Iterable接口的方法迭代器与Collection、Map集合

相关文章:

  • 2021-10-02
  • 2021-10-03
  • 2021-09-05
  • 2021-06-27
  • 2021-07-06
  • 2021-12-22
  • 2021-07-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2021-06-29
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案