Hey everyone!
Can you help me detect where's the problem?
Thanks a bunch!
package com.codegym.task.task08.task0819;
import java.util.HashSet;
import java.util.*;
/*
Set of cats
*/
public class Solution {
public static class Cat {
String name;
public Cat() {
}
public Cat (String name) {
this.name = name;
}
public String toString() {
return name;
}
}
public static void main(String[] args) {
Set<Cat> cats = createCats();
Iterator<Cat> it = cats.iterator();
Cat a = it.next();
cats.remove(a);
printCats(cats);
}
public static Set<Cat> createCats() {
Set<Cat> set = new HashSet<Cat>();
for (int i = 0; i < 3; i++) {
Cat a = new Cat("Shelby");
set.add(a);
}
return set;
}
public static void printCats(Set<Cat> cats) {
Iterator<Cat> it = cats.iterator();
for (int i = 0; i < cats.size(); i++) {
String cat = it.next().toString();
System.out.println(cat);
}
}
}