У меня есть хэш-карта с четырьмя ответами. И у меня есть для 2-х вопросов. Вот как я это делаю
// Awnsers question 1
antwoorden1.put("Hypertext Preprocessor", true);
antwoorden1.put("Hypertext PHPprocessor", false);
antwoorden1.put("Hypertext processor", false);
antwoorden1.put("Preprocessor PHP", false);
// Awnsers question 2
antwoorden2.put("Model view config", false);
antwoorden2.put("Model view connect", false);
antwoorden2.put("Model view controllers", false);
antwoorden2.put("Model view controller", true);
Теперь мне нужно получить доступ ко всей этой информации, поэтому я добавлю два HashMaps в один массив ArrayList
// Add the Hashmaps to the arrayList
alleAntwoorden.add(antwoorden1);
alleAntwoorden.add(antwoorden2);
Но как я могу пройти через ArrayList, чтобы получить ключ и значение из HashMap? Это то, что я уже пробовал.
for(int i = 0; i < alleAntwoorden.size(); i++)
{
for (Map.Entry<String, Boolean> entry : alleAntwoorden.get(i).entrySet())
{
String key = entry.getKey();
Object value = entry.getValue();
// ...
}
}
Но я всегда получаю следующий msg: несовместимые типы
Antwoorden1, antwoorden2 и alleAntwoorden определяются как:
private ArrayList<HashMap> alleAntwoorden;
private HashMap<String, Boolean> antwoorden1, antwoorden2;