Hi,
can anyone explain to me, why the last condition fails. I print the key and the value for each pair in a new line as I was supposed to do. What have I done wrong? Can anyone help me or explain to me what i have done wrong?
Best regards
Steffen
package de.codegym.task.task08.task0803;
import java.util.HashMap;
import java.util.Map;
/*
HashMap für Katzen
*/
public class Solution {
public static void main(String[] args) throws Exception {
String[] katzen = new String[]{"Tiger", "Missy", "Smokey", "Marmalade", "Oscar", "Snowball", "Boss", "Mailo", "Max", "Simba"};
HashMap<String, Katze> map = katzenZurMapHinzufügen(katzen);
for (Map.Entry<String, Katze> paar : map.entrySet()) {
System.out.println(paar.getKey() + "-" + paar.getValue());
}
}
public static HashMap<String, Katze> katzenZurMapHinzufügen(String[] cats) {
//schreib hier deinen Code
HashMap<String, Katze> in = new HashMap<String, Katze>();
int length = cats.length;
for(int i = 0; i < length; i++){
in.put(cats[i], new Katze(cats[i]));
}
return in;
}
public static class Katze {
String name;
public Katze(String name) {
this.name = name;
}
@Override
public String toString() {
return name != null ? name.toUpperCase() : null;
}
}
}