//最喜欢的学校
public ArrayList<Long> favSchool() {
school_id.clear();
Cursor mCursor = db.selectQuery("SELECT * FROM fav_school");
if (mCursor.moveToFirst()) {
{
do {
school_id.add(mCursor.getLong(mCursor
.getColumnIndex("school_id")));
} while (mCursor.moveToNext());
}
mCursor.close();
}
return school_id;
}
// All Schools
public ArrayList<Long> allSchool() {
school_id.clear();
Cursor mCursor = db.selectQuery("SELECT * FROM all_school");
if (mCursor.moveToFirst()) {
{
do {
school_id.add(mCursor.getLong(mCursor
.getColumnIndex("school_id")));
} while (mCursor.moveToNext());
}
mCursor.close();
}
return school_id;
}
the code where I am comparing both arraylists
if (favSchool() != null) {
for (int j = 0; j < favSchool().size(); j++) {
System.out.println("Equals..: " + allSchool().get(j));
}
}
I want to save the result in this int[] savedStatus.
答案 0 :(得分:0)
尝试这样的事情
ArrayList<Long> favschool = favSchool();
ArrayList<Long> allschool = allSchool();
ArrayList<Long> comonschool = new ArrayList<Long>();
if (favSchool() != null) {
for (int j = 0; j < favschool.size(); j++) {
for (int i = 0; i < allschool.size(); i++) {
if (favschool.get(j) == allschool.get(i)) {
comonschool.add(favschool.get(j));
}
}
}
}
Long[] commonSchool1 = new Long[comonschool.size()];
for (int i = 0; i < comonschool.size(); i++) {
commonSchool1[i] = comonschool.get(i);
}