Here you can find the source of countAtLevel(List aList, int aLevel)
public static int countAtLevel(List aList, int aLevel)
//package com.java2s; import java.util.*; public class Main { /**// www . j a va 2 s . c o m * Returns the number of objects at a given level in the given list hierarchy. */ public static int countAtLevel(List aList, int aLevel) { 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(); } /** * Returns the size of a list (accepts null list). */ public static int size(List aList) { return aList == null ? 0 : aList.size(); } /** * Returns the object at the given index (returns null object for null list or invalid index). */ public static <T> T get(List<T> aList, int anIndex) { return aList == null || anIndex < 0 || anIndex >= aList.size() ? null : aList.get(anIndex); } }