De-Duplication API in Java
Are there any De-Duplication API in Java? I want to elimi开发者_如何学编程nate redundant items (for e.g. duplicate fingerprints) from the database, how is it possible through Java programming?
Without more information, I would recommend just using a Set. The various flavors of Set have different pros and cons but they all have one fundamental principle. Each one is:
A collection that contains no duplicate elements.
If you add your elements to a Set and then read them back out, each unique element will only appear once.
The simple answer is that there is no Java API for removing duplicates from a database. There IS a Java API for querying and updating SQL database. It is called JDBC. But you are going to have to figure out how to detect duplicates (whatever that means) and remove them. The SQL to do this will be highly dependent on the schema of your database and the means by which you detect duplicates.
if you already know how to spot duplicates, you could use the "distinct" keyword in your sql queries.
Here's a simple example in pseudo-code. If you want a better answer, you're gonna have to give us a better question.
public void deDuplicate(Array items) {
for(int i=0; i<items.length-1; i++) {
for(int j=i+1; j<items.length; j++) {
if(items[i].equals(items[j])) {
items.removeItemAt(j);
j--;
}
}
}
}
精彩评论