(四)增强for循环遍历集合及其特性

package day23_集合;
import java.util.ArrayList;
import java.util.Collection;
public class class03_增强for循环特性与遍历集合 {
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static void main(String[] args) {
		Collection col=new ArrayList();
		for(int i=1;i<=10;i++) {
			col.add(i);
		}
		for(Object value:col) {
			System.out.println(value);
		}
		/*
		 * 增强for循环(foreach循环)相当于有一个value变量,每一次遍历出来的值赋值给value
		 * 其实增强for循环内部原理还是调用了迭代器
		 * 即使在增强for循环中尝试修改数据也无效
		 */
	}
}
发布了27 篇原创文章 · 获赞 3 · 访问量 2234

猜你喜欢

转载自blog.csdn.net/weixin_42992842/article/details/104110341