java - How to load all specific Enums to Collection? (e.g into List) -
i have enum:
public enum someenum { example_a(0), example_b(1), example_c(2), example_d(3), @getter private int bit; someenum (int bit) { this.bit= bit; }
i using in situation '0110' , e.g example_a connected '0', don't thing changes answer. represantion of enum. , i'd add together enums 1-3 (so in illustration exept first want utilize range) collection. assume for
, actiontype(i)
doesnt work me, ive started kind of enums , lack infos.
since added int bit maintain current position of element in enum
, should tell you don't need it. enum
provides access using someenum.values()[index]
. can rid of bit
field , access straight elements using previous method.
to access range of data, need add together new method specifying indexes want/need:
public static list<someenum> getrange(int init, int end) { list<someenum> results = new arraylist<someenum>(); if (!(init > end || init < 0 || end >= someenum.values().length) { (int = init, <= end; i++) { results.add(someenum.values()[i]); } } homecoming results; }
java enums
No comments:
Post a Comment