I know that HashMap doesn’t allow duplicate keys (It does allow duplicate values). However in this example that works perfectly,all the values have the same key(that means the key is not unique)Maybe I misunderstood the code.Could someone help me understand it right.
this is the code
public class PlayListManager {
//**********************************hashmap keys************************
public static final String ALL_VIDEOS = "AllVideos";
public static final String ALL_Songs = "AllSongs";
//***************************************************************************
..
...
....
while (cursor.moveToNext()) {
Songs song = new Songs();
song.songId = cursor.getString(cursor
.getColumnIndexOrThrow(MediaStore.Audio.Media._ID));
song.artist = cursor.getString(cursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
song.title = cursor.getString(cursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
song.songName = cursor
.getString(cursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME));
song.duration = Integer.parseInt(cursor.getString(cursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION)));
song.albumId = Integer.parseInt(cursor.getString(cursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID)));
song.songData = cursor.getString(cursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
//*******here it uses the same ky for all the videos?!!*************
HashMap<String, Object> songMap = new HashMap<String, Object>();
songMap.put(ALL_Songs, song);
songsList.add(songMap);
}
}