gpt4 book ai didi

java - 将两个 ArrayList 添加到一个 hashmaps 的 ArrayList

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:29:26 25 4
gpt4 key购买 nike

我有两个ArrayList,我想通过添加它们来制作一个ArrayList,两个列表的大小相同

我打算这样做。

当列表变大时,这是优化还是我可以让它变得更好和高效?

    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);

最佳答案

根据您的评论,您根本不需要 map ,您需要类和列表:

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
}

然后

List<CD> cds = new List<CD>();
CD cd = new CD("Thriller", someBitMap);
cd.getTracks().add(new Track("I'm bad", someMusic));
cds.add(cd);

关于java - 将两个 ArrayList 添加到一个 hashmaps 的 ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16461555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com