count Occurrence of a string in a string List - Android java.util

Android examples for java.util:List

Description

count Occurrence of a string in a string List

Demo Code


//package com.java2s;

import java.util.Iterator;
import java.util.List;

public class Main {
    public static void main(String[] argv) throws Exception {
        List valueList = java.util.Arrays.asList("asdf", "java2s.com");
        int value = 2;
        System.out.println(countOccurrence(valueList, value));
    }/*from   ww w  .j a v  a2  s  .c o m*/

    public static int countOccurrence(List<Integer> valueList, int value) {
        int count = 0;
        Iterator<Integer> iterValueList = valueList.iterator();
        while (iterValueList.hasNext()) {
            int vaInList = iterValueList.next();
            if (vaInList == value) {
                count++;
            }
        }
        return count;
    }
}

Related Tutorials