如何从ArrayList中&LT特定数据;整数GT;在android系统 [英] how to remove particular data from ArrayList<Integer> in android

查看:141
本文介绍了如何从ArrayList中&LT特定数据;整数GT;在android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组列表,其中包含像2,3,4,5,6一些值。现在该怎么检查值是present并希望删除特定值。请大家帮我做到这一点。 TNX提前。

I have one Array List and contains some values like 2,3,4,5,6. now how to check if the value is present and want to delete that particular Value. please help me to do this. tnx in advance.

我试过了,

ArrayList<Integer> Positions=new ArrayList<Integer>();
Positions.remove(6);

但它显示了一个错误。

but it shows an error.

推荐答案

Positions.remove(6); 删除特定位置的项目

所以,首先你必须使用循环来比较ArrayList中的项目,并获得该项目的位置,并调用 Positions.remove(ArrayList中在该项目的位置)。

So first you have to compare the item in arraylist using for loop and get the position of that item and call Positions.remove(that Item Position in ArrayList).

试试这个code。

ArrayList<Integer> positions = new ArrayList<Integer>();
positions.add(3); // add some sample values
positions.add(6); // add some sample values
positions.add(1); // add some sample values
positions.add(2); // add some sample values
positions.add(6);

for(int i=0;i<positions.size();i++)
{
    if(positions.get(i) == 6)
    {
        positions.remove(i);
    }
}

Log.i("========== After Remove ",":: "+positions.toString());

输出:I / ==========删除后(309)::: [3,1,2]

这篇关于如何从ArrayList中&LT特定数据;整数GT;在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆