howisitpossibletodeclareandinitializeanarrayofconstantsinjava,without using enums?
staticfinaltype [ ] arrayofconstants=new type [ 10 ]; //not an array of constants
ifyouwanttocreateanimmutablearray,no,you cannot.allarraysinjavaaremutable。
ifyoujustwanttopredefinethearrayinyourclass,you can do it:
privatestaticfinalint [ ] my _ array={ 10,20,30,40,50 };
herewecreatedapredefinedarraymy _ arrayoflength 5,somy _ array [0] I S10 and soon.becarefulthoughaseventhemy _ arrayfielday thisdoesnotmeanthatarrayelementscouldnotbechanged.thus it ' sbetternottoexposesucharraytopublicorprotectedmodifier。