我有兩個ArrayLists,我想刪除第一個ArrayList的所有對象,並引用第二個ArrayList。我知道我可以使用removeAll()方法,但它返回false.Both ArrayLists是相同的類型。的removeAll()的任何替代ArrayList removeAll()返回false。任何替代品?
@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];
它是否會返回'false',因爲它是空的開始? –
'removeAll'返回false,因爲'dataList'和'taskDataList'不包含共同的元素。正如@JoeC所說,一個很好的選擇是,其中至少有一個是空的 –