Question: Java Programming: I created this program to remove the duplicate names from a text file. But when I run it, it does not do that.

Java Programming: I created this program to remove the duplicate names from a text file. But when I run it, it does not do that. I. Have tried to see what I can change but I cannot find what is needed to be changed, the result is in the bottom please help me thank you in advance

import java.io.*; import java.util.HashSet; public class RemoveDup { public static void main(String[] args) throws IOException { HashSet people = new HashSet<>(); File file = new File("C:\\Users\\pimpd\\OneDrive\\Desktop\ ames.txt"); //Using buffered reader to read the names.txt file BufferedReader br = new BufferedReader(new FileReader(file)); String temp; System.out.println("Names in file: "); //here we will add all the names to the HashSet while((temp = br.readLine()) != null){ people.add(temp); System.out.println(temp); } System.out.println(); br.close(); System.out.println("People: "); //use for loop to print all the names with no duplicates. for(String str:people) System.out.println(str); } } 

result:

Names in file:

Pedro

Juan

Rosa

Greg

Pedro

People:

Pedro

Pedro

Juan

Rosa

Greg

Process finished with exit code 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!