I need to write an expression without if, because I use the ternary operator
if (dictionary.containsKey(key)) { dictionary.put(key, dictionary.get(key) + 1); } else { dictionary.put(key, 1); } I write it this way:
(dictionary.containsKey(key)) ? (dictionary.put(key, dictionary.get(key) + 1)) : (dictionary.put(key, 1)); And it gives the error "Not a statement", what to do?
dictionary.put(key, dictionary.containsKey(key) ? dictionary.get(key) + 1 : 1);- ArchDemon