All conditions are met and the code is working fine. What is wrong with the validator?
package com.codegym.task.task08.task0819;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/*
Set of cats
*/
public class Solution {
public static void main(String[] args) {
Set<Cat> cats = createCats();
Iterator<Cat> it = cats.iterator();
while (it.hasNext())
if (it.next().name == "Tom") it.remove();
printCats(cats);
}
public static Set<Cat> createCats() {
HashSet<Cat> catSet = new HashSet<>();
Cat tom = new Cat();
tom.name = "Tom";
Cat alisa = new Cat();
alisa.name = "Alisa";
Cat marusia = new Cat();
marusia.name = "Marusia";
catSet.add(tom);
catSet.add(alisa);
catSet.add(marusia);
return catSet;
}
public static void printCats(Set<Cat> cats) {
for (Cat cat:cats) {
System.out.println(cat);
//System.out.println("Cat's name: " + cat.name);
}
}
public static class Cat {
String name;
// public Cat(String xname){
// name = xname;
// }
}
}