Introduction to new features in JDK5.0:
generic type (generics);
Enhanced "for" loops (enhanced for loop);
Automatic packing/automatic unpacking (autoboxing/unboxing);
Type safety enumeration (type safe enums);
Static import (statically import);
Variable parameters (Var args);
Enhanced for Loop:
The addition of the For-each loop simplifies the traversal of the collection
Its syntax is as follows:
for (type Element:array) {
SYSTEM.OUT.PRINTLN (Element);
}
When iterating through a collection or array, if you need to access the index of a collection or array, you end up looping or iterating using the old-fashioned way, rather than using an enhanced for loop because it loses subscript information.
Automatic boxing/unpacking greatly facilitates the role of basic type data and their wrapper classes.
Automatic Boxing: The base type is automatically converted to the wrapper class. (int >> Integer)
Automatic unpacking: The wrapper class is automatically converted to the basic type. (Integer >> int)
Java record -77-enhanced for loop and auto-unboxing