0

I have created a class and an enum inside the class.

public class Constants {     
    public enum ConstantsEnum {      
        CONSTANT_1(new String[]{"A","B","C"}),
        CONSTANT_2(new String[]{"D","E","F"}),      
        CONSTANT_3(new String[]{"G","H","I"});      

        private final String[] value;      
        ConstantsEnum (String[] value) {
            this.value=value;         
        }
    } 
}

In a different class in same package,

I want to fetch the value of each array constants as mentioned below :

public Class Test{ 
    public static void main(String[] args) { 
        for(int count=0;count<=3;count++){ 
            switch(count){ 
                case 1 : //iterate first array constant from enum 
                    break;              
                case 2 : //iterate second array constant from enum 
                    break; 
                default : break; 
            } 
        } 
    } 
}

I have tried to fetch the first array enum as mentioned below :

Enum a1 = Constants.ConstantsEnum.values()[0];

But, I am unable to fetch the array elements.

Please suggest.

QBrute
  • 4,405
  • 6
  • 34
  • 40
nishi kishor
  • 3
  • 1
  • 7

0 Answers0