When you call put
on the map of type Map <Integer,String>
, you will get the String returned. So when you do this:
new HashMap<Integer,String>().put(songID, songList.get(i).name);
it will return a String
and when you try to assign it to a map
Map<Integer,String> map
compiler throws an error,
Type mismatch: cannot convert from String to Map
Here is the signature of put method form javadocs:
public V put(K key,
V value)
you need to break down the this complex problematic statement:
Map<Integer,String> map = new HashMap<Integer,String>().put(songID, songList.get(i).name);
to something like:
Map<Integer,String> map = new HashMap<Integer,String>();
map.put(songID, songList.get(i).name);