List variables in Java -


okay, might not right title, here's i'm thinking. looking way loop through set of variables. example, i'm thinking in game there series of things unlock, , when entered "unlocked" or show had unlocked , only had unlocked. show only booleans false.

in java, there no easy way variable based on name. can do, however, store variables in hashmap. accomplish want.

hashmap<string, boolean> vars = new hashmap<>(); vars.put("test1", true); // make new variable vars.get("test1"); // variable's value 

if want store variable type, change statement creates list of variables.

hashmap<string, object> vars = new hashmap<>(); 


find only booleans false, can iterate on hashmap, so:

for(entry<string, boolean> entry : vars.entryset()) {     string key = entry.getkey();     boolean value = entry.getvalue();      if(!value) {         system.out.println(key + " false");     } } 

there comprehensive tutorial here, if want learn more maps in java.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -