Skip to content Skip to sidebar Skip to footer

How To Remove A String From Arraylist Of Strings, Android

I created an arraylist of strings List textArray = new ArrayList(); and then I added the strings(which I am getting from edittext) to textArray as foll

Solution 1:

You can call one of:

to remove all entries

textArray.clear();

to remove from a specific position (e.g. first item)

textArray.remove(0);

to remove a specific string (that equals yours)

textArray.remove("myString");

Solution 2:

Try this..

Getting position from the textArray array list

intpos = textArray.indexOf(text);

and then remove from the string position

    textArray.remove(pos);

because we cannot directly remove the string. we can remove the string contains position.

Solution 3:

You can do it with more then one way as per your need.

textArray.clear(); 

It will clear whole ArrayList.

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

textArray.remove(INDEX TO REMOVE);

Solution 4:

Try This

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

to remove

textArray.remove(text);

Post a Comment for "How To Remove A String From Arraylist Of Strings, Android"