Here you can find the source of containsOnly(List elements, Class clazz)
public static boolean containsOnly(List elements, Class clazz)
//package com.java2s; /******************************************************************************* * Copyright (c) 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * /*from w ww . j a v a2 s .co m*/ * Contributors: * IBM Corporation - initial API and implementation * Zend Technologies *******************************************************************************/ import java.util.Iterator; import java.util.List; public class Main { public static boolean containsOnly(List elements, Class clazz) { if (elements.isEmpty()) return false; for (Iterator iter = elements.iterator(); iter.hasNext();) { // if (!clazz.isAssignableFrom(iter.next().getClass())) if (!clazz.isAssignableFrom(iter.next().getClass())) return false; } return true; } }