mp.put(str.substring(i, i + k), mp.get(str.substring(i, i + k)) == null ? 1 : mp.get(str.substring(i, i + k)) + 1); ...