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 :: java abstract method 
Java :: junit maven dependency 
Java :: java final method 
Java :: alert dialog not displayed android 
Java :: synchronized block in java 
Java :: how to draw a circle in java swing 
Java :: java string start with substring 
Java :: java how to write something on the console with scanner 
Java :: can you use java in unity 
Java :: first and last element of array java 
Java :: java get class by string name 
Java :: java 8 stream add to list 
Java :: button height is not increase in android studio 
Java :: spring mock Streamble of object 
Java :: spring amqp exchange not found 
Sql :: magento 2 order delete from db 
Sql :: change nls_date_format 
Sql :: set password for postgres user ubuntu 
Sql :: sql ignore accents 
Sql :: copy table oracle 
Sql :: finding duplicate column values in table with sql 
Sql :: alembic.util.exc.CommandError: Target database is not up to date. 
Sql :: how to remove tables from postgresql 
Sql :: how to install postgresql on wsl 
Sql :: mysql connectorj maven de 
Sql :: oracle search stored procedures for text 
Sql :: find names starting with vowels in sql 
Sql :: sql getdate date only 
Sql :: mysql remove unique constraint 
Sql :: mysql slave status 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =