In: Computer Science
Write a Java program to do the following: Ask the user to enter 10 first names (one word - no hyphen or apostrophe) using the keyboard.
1) Display the list of names one per line on the Console.
2) Display the names again, after eliminating duplicates using a HashSet (Your code MUST use HashSet).
#source code:
import java.util.*;
public class Test{
public static void main(String args[]){
Scanner input=new Scanner(System.in);
String[] data=new String[10];
for(int i=0;i<10;i++){
System.out.print("Enter input string"+(i+1)+": ");
data[i]=input.next();
}
System.out.println("User Enter Data:");
for(int i=0;i<10;i++){
System.out.println(data[i]);
}
HashSet<String> userData = new HashSet<>(Arrays.asList(data));
System.out.println("After using hashset:");
for(String datasub:userData){
System.out.println(datasub);
}
}
}
#output:
#if you have any doubt or more information needed comment below..i will respond as possible as soon..thanks...