在Java中将Long Value转换为数组

时间:2014-02-21 13:52:26

标签: android cursor compare

  • 我有两个很长的arraylist,我正在比较两个数组ID 这是相同的然后我想将其转换为int的array [],但我 无法做到这一点。这是我的代码请帮帮我

//最喜欢的学校

   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.

1 个答案:

答案 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);
    }