- 我
- 有两个长数组列表,我正在比较两个数组 id这是相同的,然后我想将其转换为 int 的数组[],但是我做不到。这是我的代码,请帮助我
最喜欢的学校
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.
尝试这样的事情
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);
}