Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ArrayList filter based on some condition in android

Tags:

java

android

I have an ArrayList in android which contains several names. Suppose user typed R, so I want to calculate how many names are there in the ArrayList which starts with R. for example if arraylist contains Ashok, Bimal, Ram, Raju, sunita then it should return 2 as there are 2 names starts with R

like image 595
user3061048 Avatar asked Sep 19 '26 05:09

user3061048


1 Answers

    int count = 0;
    ArrayList<String> _list;//ur arraylist with names
    for (String names : _list) {
        if (names.startsWith("R")) {
            count++;
        }

    }
    System.out.println(count);
like image 90
user543 Avatar answered Sep 20 '26 18:09

user543