0

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));
         }
     }
  }
}

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

I don't know its legal or not,but it worked.Thanks to this video and this links.

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);
Community
  • 1
  • 1
Kapil M
  • 63
  • 1
  • 9

1 Answers1

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

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

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); 
akash
  • 22,664
  • 11
  • 59
  • 87