Java Iterator count(Iterator thingsToCount)

Here you can find the source of count(Iterator thingsToCount)

Description

count

License

Open Source License

Declaration

public static <THING> Map<THING, Integer> count(Iterator<THING> thingsToCount) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    public static <THING> Map<THING, Integer> count(Iterator<THING> thingsToCount) {
        Map<THING, Integer> countedThings = new HashMap<>();
        while (thingsToCount.hasNext()) {
            THING thing = thingsToCount.next();
            if (countedThings.containsKey(thing)) {
                int count = countedThings.get(thing);
                countedThings.put(thing, count + 1);
            } else {
                countedThings.put(thing, 1);
            }//from   w  w w  . jav a  2s .com
        }
        return countedThings;
    }
}

Related

  1. convertToList(Iterator iter)
  2. copy(Iterator iterator)
  3. copyIterator(Iterable iterable)
  4. copyIterator(Iterator iter)
  5. copyOf(Iterator elements)
  6. countIterator(Iterator it)
  7. createMap(Iterator iter)
  8. createPathIterator(String path)
  9. createSkipIterator(Iterable source, int count)