简体   繁体   中英

How to shorten code in Java/Android?

Is there any way to shorten this declaration code?

boolean installed1 = false;
boolean installed2 = false;
boolean installed3 = false;
boolean installed4 = false;

...etc

Yes.Use array OR ArrayList<Boolean>

boolean installed[] = {false,false,false,false};
//Access it by index i.e installed[0] 

OR

You just want to decrease the code and it's class level declaration, as default value for boolean is false

boolean installed1,installed2,installed3,installed4;

If it's local declaration,

boolean installed1,installed2,installed3,installed4;
installed1=installed2=installed3=installed4=false;

这似乎是最短的方式:

boolean installed[] = new boolean[4];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM