• Dear Guest, Please do NOT forget to join our JAVA JOBS (ONLY) FACEBOOK GROUP to be aware of latest JAVA openings, and you may also post any JAVA related queries/jobs.

How to print duplicate string in given strings?

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);

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