How to print duplicate string in given strings?

Discussion in 'Strings, I/O, Formatting, Parsing' started by chait, Mar 29, 2010.

  1. chait

    chait New Member

    string
     
  2. ramsri4ever

    ramsri4ever New Member

    Re: how to print duplicate values in given string

    import java.util.*;
    class FindDuplicates {
    public static void main(String[] args) {
    String[] str = {"chait","ram","sri","chait"};
    HashSet s = new HashSet();
    for (String str1 : str)
    if (!s.add(str1)) {
    System.out.println("Duplicate Values detected: " + str1);
    }
    System.out.println(s.size() + " distinct values: " + s);
    }
    }

    Output:
    Duplicate values detected: chait
    3 distinct values:[chait, sri, ram]

    Regards,

    Ramsri4ever.

     
  3. rammmohan

    rammmohan New Member

    G8 Brian dude
     

Share This Page