List iterator

Report a typo

You are given the class named ChatRoom that keeps a list of User objects. Your task is to write a class that will implement the UserIterator interface in the following way: the iterator must iterate only over non-blocked users, skipping the blocked ones. Also, implement the public UserIterator iterator() method in ChatRoom.

Write a program in Java 17
import java.util.*;
import java.util.stream.Collectors;

interface UserIterator {

boolean hasNext();

boolean hasPrevious();

User next();

User previous();
}

class User {
private final String name;
private boolean blocked = false;

public User(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setBlocked(boolean blocked) {
this.blocked = blocked;
}

public boolean isBlocked() {
return blocked;
}
}

class ChatRoom {
___

Create a free account to access the full topic