How to get a HashMap value with three values

I just faced the same issue and decided to map my key to an Entry. This allows for the same indexing features provided by a map while having more than one property associated with a key. I think it’s a much neater solution that creating a separate class or nesting maps.

Map<String, Entry<Action, Boolean>> actionMap = new HashMap<String, Entry<Action, Boolean>>();

actionMap.put("action_name", new SimpleEntry(action, true));

To use the data later:

Entry<Action, Boolean> actionMapEntry = actionMap.get("action_name");

if(actionMapEntry.value()) actionMapEntry.key().applyAction();

My personal use of this was a map of named functions. Having selected the function by name, the function would be run and the boolean would determine whether or not cleanup was needed in processing.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)