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
int count = 0;
ArrayList<String> _list;//ur arraylist with names
for (String names : _list) {
if (names.startsWith("R")) {
count++;
}
}
System.out.println(count);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With