Implement a max-length subscriber

Report a typo

Implement the LongestWordSubscriber subscriber that finds the longest word from a data stream.

If the data stream is empty, show null. If there are 2 or more longest words whose lengths are equal, show the first one.

Write a program in Java 17
import java.util.Scanner;
import java.util.concurrent.Flow;

class LongestWordSubscriber implements Flow.Subscriber<String> {
// Add fields if required

@Override
public void onNext(String word) {
// implement me
}

public String getLongestWord() {
// implement me
}

// Do not change methods below
@Override
public void onSubscribe(Flow.Subscription s) {
// Empty
}

@Override
public void onError(Throwable t) {
// Empty
}

@Override
public void onComplete() {
// Empty
}
}

// Do not change the class
class Main {
public static void main(String[] args) {
LongestWordSubscriber subscriber = new LongestWordSubscriber();
___

Create a free account to access the full topic