Saturday, April 12, 2014

Printing Duplicate Character|String in a Sentence ~~ Java Code Snippet

Shown below is the source code for printing duplicate character or string in a sentence. Simply pass in the char/string as a command line argument i.e. args

~~~~~~~~~~~~~~~~~~~~~~~~~
import java.util.*;
import static java.lang.System.out;

public class Duplicate
{
  public static void main(String... args)
   {

   Set<String> s  = new HashSet<String>();
for(String ss : args)

 if (!s.add(ss))
  {
out.println("Duplicate Found:" + ss);
   }

   }
}

~~~~~~~~~~~~~~~~~~~~~~~~~

No comments: