Removing duplicate names from a comma-separated list

Report a typo
Hey there! This problem might be a bit unpredictable, but give it a go and let us know how you do!
Write a Java program that reads a single string as input, representing a list of names separated by commas (with no spaces). Your program should discard all duplicate names and print all unique names in the same order they appear in the input. Note that names are case-sensitive i.e., 'John' and 'john' are considered two different names. For example, if you input 'John,Tim,John,Casey,Tim,Casey', the output should be 'John,Tim,Casey'.

Sample Input 1:

John,Tim,John,Casey,Tim,Casey

Sample Output 1:

John,Tim,Casey

Sample Input 2:

Robert,Julia,Martin,Julia,Robert

Sample Output 2:

Robert,Julia,Martin
Write a program in Java 17
import java.util.*;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Read the string input from the user
String input = scanner.nextLine();

// Split the string by commas into an array of names
String[] names = input.split(",");

// TODO: Implement a Set to keep track of unique names
// The Set interface is part of Java's collections framework and is used
// to store unique elements - duplicates are automatically disregarded
}
}
___

Create a free account to access the full topic