JDK5.0中新特性介绍:数组
泛型(Generics);安全
加强的“for”循环(Enhanced For loop);ide
自动装箱/自动拆箱(Autoboxing/unboxing);oop
类型安全的枚举(Type safe enums);spa
静态导入(Static import);element
可变参数(Var args);it
加强的for循环:for循环
For-Each循环的加入简化了集合的遍历class
其语法以下:import
For(type element : array){
System.out.println(element);
}
当遍历集合或数组的时候,若是须要访问集合或数组的下标,那么最后使用旧式的方式来实现循环或遍历,而不是使用加强的for循环,由于它失去了下标信息。
自动装箱/拆箱大大方便了基本类型数据和它们包装类的做用。
自动装箱:基本类型自动转为包装类。(int >> Integer)自动拆箱:包装类自动转为基本类型。(Integer >> int)