+ 2
For loop is used to repeat a specific code of block based upon some condition. On the other hand, for each loop is generally used to iterate upon all the items of an array/list.
Enumerations serve the purpose of representing a group of named constants in java. Enums are used when we know all possible values at compile time, such as choices on a menu, rounding modes, command line flags, etc. The main objective of enum is to define our own data types(Enumerated Data Types).
// A simple enum example where enum is declared
// outside any class (Note enum keyword instead of
// class keyword)
enum Color
{
RED, GREEN, BLUE;
}
public class Test
{
// Driver method
public static void main(String[] args)
{
Color c1 = Color.RED;
System.out.println(c1);
}
}
//Output : RED
Enum declaration can be done outside a Class or inside a Class but not inside a Method.