我将 ArrayList 作为“deletedPositions”,并且我将值传递给该 arrayList,在此之前我想检查该数组中是否存在值,如果是,那么我想删除该值,如果不存在,则在该数组中添加值清单,如何做到这一点?
我尝试使用此代码,但无法得到答案,
if(deletedPositions.isEmpty())
{
deletedPositions.add(PositionChecked);
Toast.makeText(getApplicationContext(), "Is empty ="+this.deletedPositions.size(), 1).show();
}
else
{
for(int i=0;i<deletedPositions.size();i++)
{
if(deletedPositions.get(i) == PositionChecked)
{
deletedPositions.remove(i);
Toast.makeText(getApplicationContext(), "After removeArray ="+this.deletedPositions, 1).show();
}
else
{
deletedPositions.add(PositionChecked);
Toast.makeText(getApplicationContext(), "After Added Array ="+this.deletedPositions, 1).show();
}
}
}
任何人都可以帮助我克服这个..提前谢谢,