Index Related TLDR class Recepi { String name; int difficulty ; String[] ingredients; } HashCode @Override public int hashCode() { int result = 17 result *= 31 * name.hashCode(); result *= 31 * difficulty.hashCode(); result *= 31 * ingredients.hashCode(); return result } Equals @Overrride public boolean equals(Object o) { if (this == 0) return true; if (o == null) return false; if (this.getClass() != o.getClass()) return false; Ricetta that = (Ricetta) o; return Object.equals(name, that.name) && Object.equals(difficulty, that.difficulty) && Object.equals(ingredients, that.ingredients); } Per confrontare tipi primitivi si usa: == Per confrontare degli array si usa: ? Per confrontare enum si usa: ? per confrontare oggetti si usa: equals() Compare in questo confronterò la difficoltà @Override public int compareTo(Recepi o) { if (this.difficulty > o.difficulty) return 1 if (this.difficulty < o.difficulty) return -1 else return 0 }