Java Collection Check isCollectionType(Class cls)

Here you can find the source of isCollectionType(Class cls)

Description

is Collection Type

License

Apache License

Declaration

public static boolean isCollectionType(Class<?> cls) 

Method Source Code

//package com.java2s;
/*/*from  ww  w.j  a  va  2s.co m*/
 * Copyright 2002-2013 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.List;
import java.util.Map;
import java.util.Set;

public class Main {
    public static boolean isCollectionType(Class<?> cls) {
        if (cls.isArray()) {
            return true;
        } else if (List.class.isAssignableFrom(cls)) {
            return true;
        } else if (Set.class.isAssignableFrom(cls)) {
            return true;
        } else if (Map.class.isAssignableFrom(cls)) {
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. isCollectionOrArray(final Object obj)
  2. isCollectionOrArrayType(Class typeToCheck)
  3. isCollectionType(Class aClass)
  4. isCollectionType(Class type)
  5. isCollectionType(Class cls)
  6. isCollectionType(Class type)
  7. isCollectionType(final Class cls)
  8. isCollectionType(Object obj)
  9. isCollectionType(Object obj)