java counter code example
Example 1: counter in java
HashMap<String, MutableInteger> efficientCounter = new HashMap<String, MutableInteger>();
for (String a : sArr) {
MutableInteger initValue = new MutableInteger(1);
MutableInteger oldValue = efficientCounter.put(a, initValue);
if(oldValue != null){
initValue.set(oldValue.get() + 1);
}
}
Example 2: java count
public static void main(String[] args)
{
List<Integer> list = Arrays.asList(0, 2, 4, 6,
8, 10, 12);
long total = list.stream().count();
System.out.println(total);
}