+ 2

In the below code how to access any single enum object without enhanced for loop?

public enum tuna{ raju("father","44"),neeraja("mother","40"), sankarsh("son","18"); private String desc; private String year; tuna (String description, String age) { desc=description; year=age; }

15th Jul 2017, 5:15 AM
Sanky Pal
Sanky Pal - avatar
1 Réponse
+ 1
You can access one of the values by using the full name. In your example for instance: tuna t = tuna.raju; For a code example, please see: https://code.sololearn.com/c3C5vthNhs68/?ref=app Side note: please consider following convention by Capitalizing class or enum names (Tuna vs tuna) and using ALL CAPS for final values like the enum values (RAJU vs raju), as this will make your code easier to read & understand. Code is usually written once and read more often... :)
15th Jul 2017, 1:14 PM
marit vandijk