首页 > 编程知识 正文

java什么是变量和常量,数组名是指针常量吗

时间:2023-05-05 01:22:07 阅读:113475 作者:2684

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。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。