What is the best way to print duplicate records from a file?

0 Marty Miller · June 25, 2015
Hi all,  What is the best way to locate a set of records  from a file  for example,

Avis,E,Camacho,65,Millburn,NJ.  and then print the duplicates without using nested loops.  I used the split() to remove the commas and read it into an arraylist but cant workout how to locate and print the duplicates.  Any help is greatly appreciated.

Post a Reply


Oldest  Newest  Rating
+2 Alan Johnson · June 25, 2015
Like this

        // Read this in from your file
        String input = "Avis,E,Camacho,65,E,Avis,Millburn,NJ";

        List<String> list = new ArrayList<String>();

        for (String str : input.split(",")) {
            if (list.contains(str)) {
                System.out.println(str + " is a duplicate and is already in the list");
            } else {
                // Not in the list yet, so add it
0 Marty Miller · June 27, 2015
Thank you!  Greatly Appreciated!!
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator