A sorted stream

Report a typo

Implement a method that prints out sorted elements of a given stream of strings.

Please, use the Java Stream API to solve the problem.

Sample Input 1:

class interface type enum function

Sample Output 1:

class
enum
function
interface
type
Write a program in Java 17
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

/**
* Prints sorted elements of a given stream of strings.
*
* @param wordStream the input stream of strings
*/
public static void sortAndPrint(Stream<String> wordStream) {
// write your code here
}

// Don't change the code below
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
sortAndPrint(Arrays.stream(scanner.nextLine().split("\\s+")));
}
}
___

Create a free account to access the full topic