Showing posts with label Enum. Show all posts
Showing posts with label Enum. Show all posts

Monday 11 May 2020

Kotlin - Enum Classes in Kotlin | Enum Methods | Enum Properties

Hello Friend,
              Today I am going to share about Enum class in Kotlin
 

- How to create/initialize enum classes
- methods and properties of enum classes.



Initializing enums –


Now we can easily access the color of fruits,
Enum Methods-

  1. values: This method returns a list of all the constants defined within the enum class.
  2. valueOf: This methods returns the enum constant defined in enum, matching the input string.  If the constant, is not present in the enum, then an IllegalArgumentException is thrown.

Enum Properties-

  1. ordinal: This property stores the ordinal value of the constant, which is usually a zero-based index.
  2. name: This property stores the name of the constant.
Below is the example which help us to understand the uses of Enum method and Properties.
Outputs:

Hope this will help some one.
Enjoy Coding... :)

 

Copyright @ 2013 Android Developers Blog.