mukesh patel mukesh patel - 1 year ago 105
Java Question

How can we access type and subtypes of enum in java

I need to implement following using enum.

import java.util.*;

* @author mukesh
public class MyTest {
private List<SubTypes> subTypes = new ArrayList<SubTypes>();
enum Types {
PercentArea, StackedArea, ChartSubType3;

enum SubTypes {

Types t;
private SubTypes(Types t) {
this.t = t;

public List<SubTypes> getSubTypes() {
return Collections.unmodifiableList(subTypes);

public static void main(String[] args) {
/* How can i get SubTypes based on base type ??? */

Example :
suppose in one combo i have Types -PercentArea, StackedArea, ChartSubType3 etc. and if i select PercentArea then second combo can get sub types e.g. PERSENTAREA1,PERSENTAREA2 etc
Can any one guide me how do i can retrieve all the values of subtype for given types.
A little help will guide me to achieve my goal.
Thanks in advanced.

Answer Source

I think you need something like this

private static void getSubTypes(Types type)
    SubTypes[] values = SubTypes.values();
    for(SubTypes value : values)
        if(value.t == type){
            System.out.println("found subtype "+ value);


hope this helps!

Good luck!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download