Java Collection Check isCollectionOrArray(final Class cls)

Here you can find the source of isCollectionOrArray(final Class cls)

Description

Returns true if the supplied class is a collection or an array.

License

Open Source License

Parameter

Parameter Description
cls the class to check.

Return

true if the class is a collection or an array, or false if not.

Declaration

private static boolean isCollectionOrArray(final Class<?> cls) 

Method Source Code

//package com.java2s;
/*/*from  w  w  w. j  a  va2 s .com*/
 * Copyright 2015-2018 Ping Identity Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License (GPLv2 only)
 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses>.
 */

import java.util.Collection;

public class Main {
    /**
     * Returns true if the supplied class is a collection or an array. This
     * is primarily used to determine if it's a multivalued attribute.
     *
     * @param cls the class to check.
     * @return true if the class is a collection or an array, or false if not.
     */
    private static boolean isCollectionOrArray(final Class<?> cls) {
        return (cls.isArray() && byte[].class != cls) || Collection.class.isAssignableFrom(cls);

    }
}

Related

  1. isCollection(Object object)
  2. isCollection(Object value)
  3. isCollection(String type)
  4. isCollectional(final Class type)
  5. isCollectionOrArray(Class type)
  6. isCollectionOrArray(final Object obj)
  7. isCollectionOrArrayType(Class typeToCheck)
  8. isCollectionType(Class aClass)
  9. isCollectionType(Class type)