Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how remove match items in arrayListOf kotlin

    var a = arrayListOf<String>("hello","hello","lamine")

I need remove items match and reprint it again

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you’re trying to remove items that satisfy a particular condition, you just use removeAll: a.removeAll { str -> matches(str) }.

If you’re trying to remove duplicates, you’ll need an added Set:

val deduped = a.toSet()
a.clear()
a.addAll(deduped)

or you can write

a = a.distinct()

if a is a var.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading