why is not working ,I added all animal into hashSet<>result
Loading, please wait...
package com.codegym.task.task08.task0820;
import java.util.*;
/*
Animal set
*/
public class Solution {
public static void main(String[] args){
Set cats = createCats();
Set dogs = createDogs();
Set pets = join(cats, dogs);
printPets(pets);
removeCats(pets, cats);
printPets(pets);
}
public static Set createCats() {
Cat cat1 = new Cat();
Cat cat2 = new Cat();
Cat cat3 = new Cat();
Cat cat4= new Cat();
Set set = new HashSet(Arrays.asList(cat1,cat2,cat3,cat4));
return set;
//write your code here
}
public static Set createDogs() {
//write your code here
Dog dog1 = new Dog();
Dog dog2 = new Dog();
Dog dog3 = new Dog();
Set set = new HashSet(Arrays.asList(dog1,dog2,dog3));
return set;
}
public static Set join(Set cats, Set dogs) {
//write your code here
HashSet result = new HashSet();
Collections.addAll(result,cats);
Collections.addAll(result,dogs);
return result;
}
public static void removeCats(Set pets, Set cats) {
//write your code here
ArrayList list = new ArrayList(4);
list.addAll(cats);
Iterator itr = pets.iterator();
while (itr.hasNext())
{
Object obj = itr.next();
for (Object listObj : list)
{
if (obj.equals(listObj))
{
itr.remove();
}
}
}
}
public static void printPets(Set pets) {
//write your code here
pets.forEach(System.out::println);
}
//write your code here
public static class Cat{
public Cat(){}
}
public static class Dog {
public Dog (){}
}
}