For example, I need to check if there is any data in the map , if they exist, then return otherwise download from the database.
Map<String, Data> map = Maps.newHashMap(); //Вариант 1 map.containsKey(key) ? map.get(key) : map.put(key, loadFormDatabase(key)); //Вариант 2 Data data = map.get(key); if (data == null) { data = map.put(key, loadFormDatabase(key)); } return data; Those. the question is, what will be faster: a preliminary check for the existence of a key in the map , before doing get or just get and checking for != null