0

I am trying to compare cursor data, which is extracted from a SQLite database. It just has to be one column cursor.getString(1);

However, how can I check if that column has the same value in the next cursor row? (not the next column!) Using cursor.moveToNext();?

To paraphrase, I want to find a way to check column 1 for duplicate String entries using Cursor object.

2
  • Why don't you just extract unique data, by simply using the SQL keyword DISTINCT in your query? Commented Feb 27, 2016 at 10:16
  • What is the actual problem you're trying to solve? Commented Feb 27, 2016 at 11:30

1 Answer 1

0

Based on the solution from this answer, this is the code you might want to use:

String checkedValue = cursor.getString(1);

while(cursor.moveToNext()){
    String value = cursor.getString(1);
    if(value.equals(checkedValue)){ 
        // TODO: duplicate value found, do something
        break;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.