method values() | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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")); } }

16th Nov 2020, 3:37 PM
saeedeh
2 Answers
+ 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
16th Nov 2020, 4:11 PM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 ok thank you
16th Nov 2020, 4:29 PM
saeedeh