Reegan Miranda Reegan Miranda - 1 month ago 8
Java Question

how to print all enum value in java?

enum generalInformation {
NAME {
@Override
public String toString() {
return "Name";
}
},
EDUCATION {
@Override
public String toString() {
return "Education";
}
},
EMAIL {
@Override
public String toString() {
return "Email";
}
},
PROFESSION {
@Override
public String toString() {
return "Profession";
}
},
PHONE {
@Override
public String toString() {
return "Phone";
}
}
}


I have that information are avaiable in enum.


  1. How to print all enum values like:
    print.generalInformation
    ?



That outputs:


Name

Education

Email

Phone



  1. How to pass that enum
    generalInformation
    as an arg in another function?


Answer
System.out.println(java.util.Arrays.asList(generalInformation.values()));

Your second part... Just the same as an interface or a class