September 2011
Beginner
650 pages
15h 47m
English
All enumerations automatically have two predefined methods: values( ) and valueOf( ). Their general forms are shown here:
public static enum-type[ ] values( )
public static enum-type valueOf(String str)
The values( ) method returns an array that contains a list of the enumeration constants. The valueOf( ) method returns the enumeration constant whose value corresponds to the string passed in str. In both cases, enum -type is the type of the enumeration. For example, in the case of the Transport enumeration shown earlier, the return type of Transport.valueOf(“TRAIN”) is Transport. The value returned is TRAIN. The following program demonstrates the values( ) and valueOf( ) methods:
The output from the program ...
Read now
Unlock full access