How to remove a string from arraylist strings, ANDROID

I created arraylist strings

List<String> textArray = new ArrayList<String>();

and then I added the lines (which I get from edittext) to textArray as follows

String text = editText1.getText().toString();
textArray.add(text);

Now I created a button and you need to remove the row from the array when the button is clicked. But I do not know what to do. I know for arrays of bitmap images we clear the bitmap from the array using recycling, but please suggest me remove or clear the string from arraylist.

+4
source share
4 answers

You can call one of:

delete all entries

textArray.clear();

to remove from a specific position (for example, the first element)

textArray.remove(0);

(equals yours)

textArray.remove("myString");
+19

.

textArray

int pos = textArray.indexOf(text);

    textArray.remove(pos);

. , .

+2

You can do this in more than one way to suit your needs.

textArray.clear(); 

It will clear the entire ArrayList array.

If you want to remove only some data from the index, then

textArray.remove(INDEX TO REMOVE);
+1
source

try it

String text = editText1.getText().toString();
textArray.add(text);

remove

textArray.remove(text);
0
source

All Articles