Posted October 6, 20213 yr comment_63108 Hey everyone. This is a better way to select a random entry from an enum An example of an enum group is: This is the hidden content, please Sign In or Sign Up Enums are incredibly useful for storing multiple types of data. You'll see them used in a load of places! Now, the usual way to select a random entry from your enum list would be; This is the hidden content, please Sign In or Sign Up Of course - this does work. However, why not improve it! Here is a new method for you.. I've added mine into Misc.java along with my randomItem method! This is the hidden content, please Sign In or Sign Up Now, lets select a entry from our enum using this new method! (If added in Misc.java) This is the hidden content, please Sign In or Sign Up How much cleaner is that! You **must** add .class to the end of the name in this bracket. You can then use the entry as required! E.g. This is the hidden content, please Sign In or Sign Up Hopefully you can use this to clean up some code 😛
October 29, 20222 yr comment_82683 Learning new tips and tricks as I just go down neat trick thank you
Create an account or sign in to comment