Kalpesh Kundanani
Kalpesh Kundanani

Reputation: 5763

ArrayList removeAll() returning false. any alternatives?

I have two ArrayLists and I want to remove all objects of first ArrayList with reference to second ArrayList. I know I can use removeAll() method but it is returning false.Both ArrayLists are of same type. any alternatives of removeAll()

    @Override
    protected void onPostExecute(Void aVoid) {
        super.onPostExecute(aVoid);
        if (successfullyAssigned) {
            ArrayList<CustomDataModel> dataList = adapter.getDataSet();
            Boolean deleted = dataList.removeAll(taskDataList);
            Log.d("LogTag", "deleted ? " + deleted);

            setPreference(getPrefName(), dataList);
        }
  }

 public ArrayList<CustomDataModel> getDataSet() {
    return dataSet;
}

private class AssignTask extends AsyncTask<ArrayList<CustomDataModel>, Void, Void> {
    ProgressDialog progressDialog;
    ArrayList<CustomDataModel> taskDataList;
    Boolean successfullyAssigned;


    @SafeVarargs
    @Override
    protected final Void doInBackground(ArrayList<CustomDataModel>... callData) {
        taskDataList = callData[0];

Upvotes: 0

Views: 525

Answers (1)

Leo Aso
Leo Aso

Reputation: 12513

There are three reasons this can happen

  1. One of the lists is empty.
  2. The lists do not have common elements.
  3. You did not implement CustomDataModel.equals().

Upvotes: 1

Related Questions