Collection contains Instance Of - Android java.util

Android examples for java.util:Collection Contains

Description

Collection contains Instance Of

Demo Code


//package com.book2s;
import java.util.Collection;

public class Main {
    public static void main(String[] argv) {
        Collection set = java.util.Arrays.asList("asdf", "book2s.com");
        Class clazz = String.class;
        System.out.println(containsInstanceOf(set, clazz));
    }/*from ww  w  .  j av a2 s  .  c o  m*/

    public static boolean containsInstanceOf(Collection<?> set,
            Class<?> clazz) {
        for (Object obj : set) {
            if (clazz.isInstance(obj))
                return true;
        }
        return false;
    }
}

Related Tutorials