Method to check if a Object is a Collection or not. - Java Reflection

Java examples for Reflection:Class

Description

Method to check if a Object is a Collection or not.

Demo Code


//package com.book2s;

import java.util.*;

public class Main {
    public static void main(String[] argv) {
        Object ob = "book2s.com";
        System.out.println(isCollection(ob));
    }//from ww w.  ja v a 2  s.  c o  m

    /**
     * Method to check if a Object is a Collection or not.
     * @param ob the Object to inspect.
     * @return if true the class extend or implememnt Collection.
     */
    public static boolean isCollection(Object ob) {
        return ob instanceof Collection || ob instanceof Map;
        //return ob != null && isClassCollection(ob.getClass());
    }
}

Related Tutorials