你好朋友兩個數組列表中刪除常見的元素我有兩個數組列表mArrayListMySkuVarients和mArrayListAllVarients,我想除去常見的元素構成這兩個ArrayList和存儲它第三個mArrayListCommonVarients所以下面是我的代碼針對Android
mArrayListMySkuVarients =new ArrayList<>();
mArrayListAllVarients=new ArrayList<>();
mArrayListCommonVarients=new ArrayList<>(mArrayListAllVarients);
GetProductDetail.ProductVarientData mProductVarientData=new GetProductDetail.ProductVarientData();
mProductVarientData.setSku("2");
mProductVarientData.setColor("Red");
mArrayListMySkuVarients.add(mProductVarientData);
GetProductDetail.ProductVarientData mProductVarientData1=new GetProductDetail.ProductVarientData();
mProductVarientData1.setSku("1");
mProductVarientData1.setColor("Green");
mArrayListMySkuVarients.add(mProductVarientData1);
GetProductDetail.ProductVarientData mProductVarientData2=new GetProductDetail.ProductVarientData();
mProductVarientData2.setSku("4");
mProductVarientData2.setColor("Blue");
mArrayListMySkuVarients.add(mProductVarientData2);
GetProductDetail.ProductVarientData mProductVarientData3=new GetProductDetail.ProductVarientData();
mProductVarientData3.setSku("2");
mProductVarientData3.setColor("Red");
mArrayListAllVarients.add(mProductVarientData3);
GetProductDetail.ProductVarientData mProductVarientData4=new GetProductDetail.ProductVarientData();
mProductVarientData4.setSku("1");
mProductVarientData4.setColor("Green");
mArrayListAllVarients.add(mProductVarientData4);
GetProductDetail.ProductVarientData mProductVarientData5=new GetProductDetail.ProductVarientData();
mProductVarientData5.setSku("4");
mProductVarientData4.setColor("Blue");
mArrayListAllVarients.add(mProductVarientData5);
GetProductDetail.ProductVarientData mProductVarientData6=new GetProductDetail.ProductVarientData();
mProductVarientData6.setSku("3");
mProductVarientData4.setColor("Yellow");
mArrayListAllVarients.add(mProductVarientData6);
for(GetProductDetail.ProductVarientData apv : mArrayListAllVarients) {
for (GetProductDetail.ProductVarientData pv : mArrayListMySkuVarients) {
if (apv.getSku() == pv.getSku() && apv.getColor().equalsIgnoreCase(pv.getColor())) {
mArrayListCommonVarients.remove(pv);
}
}
}
當我運行上面的代碼,它不會刪除我的重複值,它給我的所有數據在mt第三arraylist所以我怎麼能解決這個問題?你所有的建議都明顯
選中此[http://stackoverflow.com/a/29284162/3022836](http:/ /stackoverflow.com/a/29284162/3022836) – Kunu