Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

enum to int java

yourEnum.ordinal()
Comment

java enum from int

//If performance is not an issue (code is only called a few times)
//The reason this is expensive is that .values() returns an array,
//which is a copy of the original because the array might be modified.
MyEnum.values()[x]

//If performance is an issue (code is run hundreds of times)
public enum MyEnum {
    EnumValue1,
    EnumValue2;

    public static MyEnum fromInteger(int x) {
        switch(x) {
        case 0:
            return EnumValue1;
        case 1:
            return EnumValue2;
        }
        return null;
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: clear jtable rows java 
Java :: java get file from url 
Java :: jframe border 
Java :: how to convert epoch time to date in java 
Java :: public String toString() { 
Java :: how to declare an array in java 
Java :: create stream from array java 
Java :: java replace all not number 
Java :: inorder, PreOrder, PostOrder java 
Java :: replace last char in string java 
Java :: list of lists java 
Java :: JAVA HashMap get keys by values 
Java :: how to print hello world java 
Java :: permission foreground_service 
Java :: int to byte 
Java :: how to add 2 numbers in java 
Java :: java loop 
Java :: java remove duplicates 
Java :: java quotes in string 
Java :: android recyclerview item click listener 
Java :: split method in java 
Java :: android xml hide 
Java :: setting scale to big decimal java 
Java :: str.substring last 2 java 
Java :: iterate through hashMap by forEach loop 
Java :: c# or java 
Java :: viewpager2 dependency 
Java :: android application class manifest 
Java :: android kill other app programmatically by package 
Java :: java booleans 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =