I have an Arraylist with (String-)Arrays in it. Now I want to be able to delete a specific element from the Arraylist.
Here is an example arraylist:
0: [Name, , , ]
1: [Telefon, \(\d+\) \d+, DAFAE8, FF6262]
2: [E-Mail, ^[a-zA-Z0-9]+(?:(\.|_)[A-Za-z0-9!#$%&'*+/=?^`{|}~-]+)*@(?!([a-zA-Z0-9]*\.[a-zA-Z0-9]*\.[a-zA-Z0-9]*\.))(?:[A-Za-z0-9](?:[a-zA-Z0-9-]*[A-Za-z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$, DAFAE8, FF6262]
3: [Company, , , ]
4: [Test, , , ]
5: [Test2, , , ]
6: [Test3, , , ]
Now I want to delete the 5th element (the array which includes Test2). How do I accomplish that?
I already tried the following things:
public static List<String[]> removeSpecificElements(List<String[]> list, int i){
list.remove(new Integer(i));
return list;
}
This one doesn't throw any kind of Exception, but doesn't work either.
public static List<String[]> removeSpecificElements(List<String[]> list, int i){
list.remove(i);
return list;
}
This one throws ArrayIndexOutOfBounds.
public static List<String[]> removeSpecificElements(List<String[]> list, int i){
Iterator<String[]> itr = list.iterator();
itr.next();
for (int x = 0; x < i; x++){
itr.next();
System.out.println(itr);
}
itr.remove();
return list;
}
And this one always removes the first element.
Could you please help me?