+ 1
method values()
hi guys I have some questions about this code: 1) why do we use : in the loop?what does it do? 2) what does valueof() do exactly?Is that for sending parameter? enum Color { RED, GREEN, BLUE; } public class Test { public static void main(String[] args) { Color[] arr= Color.values(); for (Color col : arr) { System.out.println(col.name()); } System.out.println(Color.valueOf("RED")); } }
2 Respuestas
+ 1
1) That's according syntax of "for each loop (short form loop for iteratables, collections, arrays..)"
That's a syntax :
for(datatype variable : a collection) {..}
2)valueOf() return enum value from defined enum...
Edit : saeedeh
For more refer this :
https://www.javatpoint.com/enum-in-java
0
Jayakrishna🇮🇳 ok thank you