Java examples for Language Basics:for
The enhanced forloop has this format:
for (type identifier : array)
{
statements...
}
The type identifies the type of the elements in the array.
The identifier provides a name for a local variable that is used to access each element.
public class Main { public static void main(String[] args) { String[] days = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; for (String day : days) { System.out.println(day);//from w ww . ja v a 2s . c o m } } }