xxxxxxxxxx
ans.put(key, new ArrayList());
ans.get(key).add(s);
ans is the HashMap and s is a String object.
HashMap itself has no add method. By using get you access the value associated to the given key. Which, in your case, is an ArrayList. The add method belongs to this ArrayList value.