I'm trying to add mImageViews / soundsRawResIds elements of these two arrays in imageCountru
the mImageViews collection must be added to the imageCountru as keys

public Map<Integer, Integer> imageCountru = new HashMap<>(); ArrayList<Integer> soundsRawResIds = new ArrayList<>(); ArrayList<Integer> mImageViews = new ArrayList<>(); public void ininitialize() { mImageViews.add(R.drawable.russia); mImageViews.add(R.drawable.litva); mImageViews.add(R.drawable.litva); mImageViews.add(R.drawable.litva); mImageViews.add(R.drawable.litva); mImageViews.add(R.drawable.litva); mImageViews.add(R.drawable.litva); soundsRawResIds.add(R.raw.belarus); soundsRawResIds.add(R.raw.russian); soundsRawResIds.add(R.raw.japan); soundsRawResIds.add(R.raw.litva); soundsRawResIds.add(R.raw.england); soundsRawResIds.add(R.raw.finlandia); soundsRawResIds.add(R.raw.france); } public void add() { //тут пытаюсь добавить mImageViews/soundsRawResIds элементы этих двух массивов в imageCountru } 

in another class, I am displaying only the key values

  void some() { for (Iterator<Map.Entry<Integer, Integer>> it = ima.imageCountru.entrySet().iterator(); it.hasNext(); ) { Map.Entry<Integer, Integer> entry = it.next(); int n = entry.getValue(); mAdapter.addItem(n); } } 
  • Um, what key do you want to add? - GenCloud
  • @GenCloud mImageViews collection must be added to the imageCountru in the form of keys - upward
  • And what will be the values ​​in imageCountru ? - Nofate

1 answer 1

 ArrayList<Integer> mImageViews = new ArrayList<>(); Map<Integer, Integer> imageCountru = new HashMap<>(); //блок записи add imageCountru.put(mImageViews, value); 
  • Well, see for yourself what you already want to pull out of the map by the key - GenCloud
  • one
    it is damn bad to add values ​​with mutable keys to a map, there is a chance they never get from there. - Artem Konovalov
  • Please try to write more detailed answers. I am sure the author of the question would be grateful for your expert commentary on the code above. - Nicolas Chabanovsky