Не работает проверка

В коде не работает проверка, когда в консоли выдаёт 3 одинаковых предмета

public class casino {

public static String getIngot(){
    String[] ingots = new String[]{"iron","gold","diamond"};
    int n = (int)Math.floor(Math.random() * ingots.length);

    if(ingots[n] == "iron"){
        return "[I]";
    }
    else if(ingots[n] == "gold"){
        return "[G]";
    }
    else if(ingots[n] == "diamond"){
        return "[D]";
    }
    return null;
}

public static void main(String[] args) {

    String slots = (getIngot()+getIngot()+getIngot());
    System.out.println(slots);  
    if (slots == "[I][I][I]"){
        System.out.println("IRON");
    }
    if (slots == "[G][G][G]"){
        System.out.println("GOLD");
    }
    if (slots == "[D][D][D]"){
        System.out.println("DIAMOND");      
    }

  }
}

Ответы (1 шт):

Автор решения: Алексей г
public static String getIngot() {
        String[] ingots = new String[]{"iron", "gold", "diamond"};
        int n = (int) Math.floor(Math.random() * ingots.length);

        switch (ingots[n]) {
            case "iron":
                return "[I]";
            case "gold":
                return "[G]";
            case "diamond":
                return "[D]";
        }
        return null;
    }

    public static void main(String[] args) {

        String slots = (getIngot() + getIngot() + getIngot());
        System.out.println(slots);
        if (slots.equals("[I][I][I]")) {
            System.out.println("IRON");
        }
        if (slots.equals("[G][G][G]")) {
            System.out.println("GOLD");
        }
        if (slots.equals("[D][D][D]")) {
            System.out.println("DIAMOND");
        }
    }
→ Ссылка