Write a program which takes thee list of names, and print outall the names only once. The expected runtime should be O(n) wheren is the total number of names in the lists. You don’t have to sortthe list. Use appropriate data structure to store the names, so addall data to the collection only once efficiently. The read-in listmethod and list1, list2, list3 is given. You may assume that theexpected runtime of searching or inserting into a hash table isO(1). Do not call the list’s contains method, because it slows downthe run time.
please use the code below to test it
import java.io.*;import java.util.*;public class A4PrintName{ public static List<String> readInFile(String filename){ List<String> input = new ArrayList<>(); try (Scanner sin = new Scanner(new FileReader(filename))){ while (sin.hasNextLine()){ input.add(sin.nextLine()); } } catch (FileNotFoundException e){ e.printStackTrace(); } return input; } public static void main(String[] args){ List<String> namelist1 = readInFile(“A4input1.txt”); List<String> namelist2 = readInFile(“A4input2.txt”); List<String> namelist3 = readInFile(“A4input3.txt”); Set<String> names; //your code starts here… you may write any function where you need. }}
list 1
AmyAndyAnnaBenBenjaminCatherineEmmaJamesJessieJenniferJohnKarenKellyKyleLenaLiamMaryMiaSteveWilliam
list 2
AmyAndyAnneBenBenjaminCatherineDavidEmmaJamesJessieJenniferJennyJohnKarenKellyKyleMaryMiaSelinaTinaWilliam
list 3
AmyAnaAnneDaveGeorgeSelinaShawnWilliam
Expert Answer
Answer to Write a program which takes thee list of names, and print out all the names only once. The expected runtime should be O(…