Maybe you can help me? If i copy this code into a new Window in IntelliJ, the order of the entries is mixed up and starts with "snowball". I guess this is the reason why i dont pass the last condition.
This is the Output:
Snowball - SNOWBALL
Boss - BOSS
Mailo - MAILO
Missy - MISSY
Simba - SIMBA
Max - MAX
Smokey - SMOKEY
Tiger - TIGER
Marmalade - MARMALADE
Oscar - OSCAR
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) {
HashMap<String, Katze> map2 = new HashMap<String, Katze>();
for (int i = 0; i < cats.length; i++){
String key = cats[i];
map2.put(key, new Katze(key));
}
return map2;
//schreib hier deinen Code
}
public static class Katze {
String name;
public Katze(String name) {
this.name = name;
}
@Override
public String toString() {
return name != null ? name.toUpperCase() : null;
}
}
}