Source Code : Find duplication
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Find duplication

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
public class MatchDuplicateWords {
public static void main(String args[]) {
hasDuplicate("pizza pizza");
hasDuplicate("Faster pussycat kill kill");
hasDuplicate("The mayor of of simpleton");
hasDuplicate("Never Never Never Never Never");
hasDuplicate("222 2222");
hasDuplicate("sara sarah");
hasDuplicate("Faster pussycat kill, kill");
hasDuplicate(". .");
}
public static boolean hasDuplicate(String phrase) {
boolean retval = false;
String duplicatePattern = "\b(\w+) \1\b";
Pattern p = null;
try {
p = Pattern.compile(duplicatePattern);
} catch (PatternSyntaxException pex) {
pex.printStackTrace();
System.exit(0);
}
int matches = 0;
Matcher m = p.matcher(phrase);
String val = null;
while (m.find()) {
retval = true;
val = ":" + m.group() + ":";
System.out.println(val);
matches++;
}
String msg = " NO MATCH: pattern:" + phrase
+ "
regex: " + duplicatePattern;
if (retval) {
msg = " MATCH : pattern:" + phrase + "
regex: "
+ duplicatePattern;
}
System.out.println(msg + "
");
return retval;
}
}
Thank with us