Android 从 ArrayList<List<String>> 中删除项目 [英] Android Remove items from ArrayList&lt;List&lt;String&gt;&gt;

查看:37
本文介绍了Android 从 ArrayList<List<String>> 中删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Arraylist中删除项目?

How to remove items from the Arraylist?

final ArrayList<List<String>> finalArrayList = null;
buf="1,2,3,four,5,six,nine,10";
finalArrayList.add(Arrays.asList(buf.split(",")));
   for(int i = finalArrayList .size()-1 ; i >0; i--){
      for(int i1 = finalArrayList .get(i) .size()-1 ; i1 > 0; i1--){
         if(isNumeric(finalArrayList.get(i).get(i1))==true){
            Log.d("arra", finalArrayList.get(i).get(i1).toString());
            finalArrayList.remove(finalArrayList.get(i).get(i1));
         }
     }
  }
}

如果有人链接到声明和解释 tuts 也很棒.

It would also be great if someone link to declaration and explanation tuts.

我不知道它是否合法,但它有效.感谢 此视频此链接.

final ArrayList<List<String>> finalArrayList = null;
String[] strn = buf.split(",");
ArrayList<String> names = new ArrayList<String> ();

for(int i =0;i< strn.length;i++){
names.add(strn[i]);
//System.out.println(names);
}
Iterator<String> i = names.iterator();
while(i.hasNext()){
String s = i.next();
//System.out.println("Printing>>>" + s);
try{
    if(isNumeric(s)==true){
        System.out.println("Removing...");
        i.remove();
    }
    else{
        System.out.println("No numeric");
    }
}catch(Exception e){
    System.out.println("On Removing Error===>" +  e.getMessage());
}
}
finalArrayList.add(names);

推荐答案

 finalArrayList.remove(finalArrayList.get(i).get(i1));

这里 finalArrayList.get(i).get(i1) 会在 listi1th 位置给你 Stringcode> 位于 finalArrayList

Here finalArrayList.get(i).get(i1) will give you String at i1th position of list which is there at ith position in finalArrayList

您正在尝试从 ListArrayList 中删除 String,您需要做这样的事情(好吧不是确定是否要删除它)

You are trying to remove String from ArrayList of List<String> you need to do something like this (Well not sure you want to remove it or not)

(finalArrayList.get(i)).remove(i1); 

这篇关于Android 从 ArrayList<List<String>> 中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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