Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.EventListener; import javax.swing.event.EventListenerList; public class Main { public static EventListener[] getListeners(EventListenerList listenerList, Class t) { Object[] lList = listenerList.getListenerList(); int n = getListenerCount(lList, t); EventListener[] result = (EventListener[]) java.lang.reflect.Array.newInstance(t, n); int j = 0; for (int i = lList.length - 2; i >= 0; i -= 2) { if (lList[i] == t) { result[j++] = (EventListener) lList[i + 1]; } } return result; } private static int getListenerCount(Object[] list, Class t) { int count = 0; for (int i = 0; i < list.length; i += 2) { if (t == (Class) list[i]) count++; } return count; } }