Java Utililty Methods List Count

List of utility methods to do List Count

Description

The list of methods to do List Count are organized into topic(s).

Method

intcount(List l, int from, int to, Object what)
count the number of occurences in a list
int result = 0;
while (from < to) {
    Object which = l.get(from++);
    if (equals(which, what))
        result++;
return result;
Integercount(List values)
Derives the number of values for the given list of values.
if (values == null || values.size() == 0) {
    return 0;
return values.size();
Mapcount(List lines)
count
Map<String, Integer> result = new HashMap<String, Integer>();
for (String line : lines) {
    if (line.toLowerCase().contains(DEBUG_KEY)) {
        Integer currentCount = (result.get(DEBUG_KEY) == null ? 0 : result.get(DEBUG_KEY));
        result.put(DEBUG_KEY, currentCount + 1);
    } else if (line.toLowerCase().contains(INFO_KEY)) {
        Integer currentCount = (result.get(INFO_KEY) == null ? 0 : result.get(INFO_KEY));
        result.put(INFO_KEY, currentCount + 1);
...
intcountAtLevel(List aList, int aLevel)
Returns the number of objects at a given level in the given list hierarchy.
if (aLevel < 0)
    return 1;
if (aLevel > 0) {
    int count = 0;
    for (int i = 0, iMax = aList.size(); i < iMax; i++)
        count += countAtLevel((List) aList.get(i), aLevel - 1);
    return count;
return aList.size();
intcountNumber(List list, int number)
count Number
int occurrences = Collections.frequency(list, number);
return occurrences;
intcountOccurances(List encodings, int value)
count Occurances
int count = 0;
for (int[] next : encodings) {
    if (contains(next, value)) {
        count++;
return count;
intcountOccurence(List valueList, int value)
count Occurence
int count = 0;
Iterator<Integer> iterValueList = valueList.iterator();
while (iterValueList.hasNext()) {
    int vaInList = iterValueList.next();
    if (vaInList == value) {
        count++;
return count;
intcountOccurrencesOf(Object comparisonObject, List list)
Return an integer representing the number of occurrences (using equals()) of the specified object in the specified list.
int instances = 0;
boolean comparisonObjectIsNull = comparisonObject == null;
if (list != null) {
    for (int i = 0; i < list.size(); i++) {
        Object listObject = list.get(i);
        if ((comparisonObjectIsNull & listObject == null)
                || (!comparisonObjectIsNull && comparisonObject.equals(listObject))) {
            instances++;
...