如何比较两个List <class>从sqlite获取?

时间:2017-11-27 14:59:29

标签: android sqlite android-sqlite

让我们说我有一张名为Api的表,就像这样:

id | flag | audit
1  |   1  |   12
2  |   1  |   12
3  |   0  |   12
4  |   1  |  1234
5  |   1  |  1234
6  |   1  |  1234

使用此代码我可以计算audit列:

//DBHelper
public List<Contact> getaudit(){
    List<Contact> contactList = new ArrayList<>();
    String selectQuery = "select audit, count(audit) FROM Api group by audit";

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

    if (cursor.moveToFirst()) {
        do {
            Contact contact = new Contact();
            contact.setName((cursor.getString(0)));
            contact.setAudit(cursor.getString(1));
            contactList.add(contact);
        } while (cursor.moveToNext());
    }
    return contactList;
}

//MainActivity.java

List<Contact> contacts = db.getaudit();
for (Contact cn : contacts) {
    String log = "Audit Name "+cn.getName()+" ,Counting " + cn.getAudit();
    // Writing Contacts to log
    Log.d("Name: ", log);
}

logcat告诉我:

Audit Name 12 ,Counting 3
Audit Name 1234 ,Counting 3

我会使用相同的代码来获取group by audit的标记,因此我有2个List,但我不知道如何使用if statement和2 List&lt;&gt;

问题是:

我想比较flag的count 1是否与Audit group by查询相同,Logcat会告诉我Same

像:

id | flag | audit
1  |   1  |   12
2  |   1  |   12  // audit 12 = 3(count) but flag = 2(count)
3  |   0  |   12
4  |   1  |  1234
5  |   1  |  1234 // audit 1234 = 3(count) and flag = 3(count) output Same
6  |   1  |  1234

有没有办法做到这一点?
请指导我。

0 个答案:

没有答案