I have two ArrayList and I want to make one ArrayList by adding them, both lists have same size
I am going to do it this way.
Is this optimized or can I make it better and efficient when the lists become large?
i.e.
private ArrayList<Bitmap> imageFile= new ArrayList<Bitmap>();
imageFile.add(xy);
imageFile.add(ab);
imageFile.add(cd);
private ArrayList<MediaPlayer> musicFile= new ArrayList<MediaPlayer>();
musicFile.add(mm);
musicFile.add(nn);
musicFile.add(ll);
private HashMap<Bitmap, MediaPlayer> mappedFiles= new HashMap<Bitmap, MediaPlayer>();
mappedFiles.put(imageFile.get(i),musicFile.get(i))
private ArrayList<HashMap<Bitmap, MediaPlayer>> imageMusic= new ArrayList<HashMap<Bitmap, MediaPlayer>>();
imageMusic.add(mappedFiles);
Based on your comment, you don't want a map at all, you want classes and Lists:
public class Track {
private final String name;
private final MediaPlayer music;
public Track (String name, MediaPlayer music) {
this.name = name;
this.music = music;
}
// getters omitted
}
public class CD {
private final String name;
private final BitMap image;
private final List<Track> tracks = new ArrayList<Track>();
public CD (String name, BitMap image) {
this.name = name;
this.image = image;
}
public List<Track> getTracks() {
return tracks;
}
// other getters omitted
}
Then
List<CD> cds = new List<CD>();
CD cd = new CD("Thriller", someBitMap);
cd.getTracks().add(new Track("I'm bad", someMusic));
cds.add(cd);
Write a wrapper for Bitmap , and Media Player yourself
class Media {
Bitmap bitmap;
MediaPlayer mediaPlayer
}
When you have to map bitmap and mediaplayer, create an object of this class and push them to an ArrayList<Media> ?
Why do you want to complicate by using HashMap of Bitmap of MediaPlayer?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With