getting a strange error from intelliJ. Can someone please explain what I've done wrong here?
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();
Set<Cat> copycat = new HashSet<Cat>(cats);
Iterator<Cat> it = copycat.iterator();
Cat delete = new Cat();
while (it.hasNext()){
delete = it.next();
cats.remove(delete);
break;
}
printCats(cats);
}
public static Set<Cat> createCats() {
Set<Cat> ccats = new HashSet<Cat>();
Cat james = new Cat();
Cat johnny = new Cat();
Cat boris = new Cat();
ccats.add(james);
ccats.add(johnny);
ccats.add(boris);
return ccats;
}
public static void printCats(Set<Cat> cats) {
for (Cat catlist : cats) {
System.out.println(catlist);
}
}
public static class Cat {}
}
Please help
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
andy 6473
31 August 2020, 16:46
your code is working
0
Crawler_RG
31 August 2020, 14:16
main
createCats()
0
Misiu
31 August 2020, 12:28
Output correct. No errors in IntelliJ.
0