Java enums

working with java enums

Search for: working with java enums

jdk enum reference

java comparing strings to enums

Search for: java comparing strings to enums


public class SatSectionType
{
	public enum SectionTypeEnum {
		CR1, CR2, CR3, M1, M2, M3, W1, W2, W3, G
	}
	
        //unrelated methods
	public SatSectionType(){}
	public String f_SatSectionType_id;
	public int f_number_of_questions;
	public String f_sectiontype_name;
	public String f_sectiontype_abbreviation;

	//Comparing a string to its enum value
	static boolean isM2(String type)
	{
		return (SectionTypeEnum.M2 == SectionTypeEnum.valueOf(type));
	}
}

//built in valueOf method
SomeEnumType x = SomeEnumType.valueOf(String x);

//Predefined statics
SomeEnumType.Option1
SomeEnumType.Option2
//etc

//Predefined collections
SomeEnumType.values() //returns an enumerable collection