Java Collection Check isCollectionType(Object obj)

Here you can find the source of isCollectionType(Object obj)

Description

This method checks whether the JSON being parse is a container class.

License

Open Source License

Parameter

Parameter Description
obj the object to check what type it is

Return

true if it is a container class, false otherwise

Declaration

static boolean isCollectionType(Object obj) 

Method Source Code


//package com.java2s;
import java.util.Collection;
import java.util.List;

public class Main {
    /**//from ww  w .j a  va 2 s  .c  o m
     * This method checks whether the JSON being parse is a container class. This
     * prevents malforming the returning JSON string.
     * @param obj the object to check what type it is
     * @return true if it is a container class, false otherwise
     */
    static boolean isCollectionType(Object obj) {
        if (obj instanceof List<?>) {
            return true;
        } else if (obj instanceof Collection<?>) {
            return true;
        } // add other statements here
        return false;
    }
}

Related

  1. isCollectionType(Class cls)
  2. isCollectionType(Class cls)
  3. isCollectionType(Class type)
  4. isCollectionType(final Class cls)
  5. isCollectionType(Object obj)
  6. isCollectionType(Object propertyValue)
  7. isCollectionType(Object value)
  8. isCollectionTypeHomogenous(final Collection collection, final Class expectedType)
  9. isCompatibleTypes(Collection a, Collection b)