is object an Array - Java Collection Framework

Java examples for Collection Framework:Array Element

Description

is object an Array

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        Object o = "java2s.com";
        System.out.println(isArray(o));
    }/*from   ww  w.  j  av a  2 s .c o m*/

    public static boolean isArray(Object o) {
        if (o instanceof char[]) {// char
            return true;
        } else if (o instanceof boolean[]) {// boolean
            return true;
        } else if (o instanceof byte[]) {// byte
            return true;
        } else if (o instanceof short[]) {// short
            return true;
        } else if (o instanceof int[]) {// int
            return true;
        } else if (o instanceof long[]) {// long
            return true;
        } else if (o instanceof float[]) {// float
            return true;
        } else if (o instanceof double[]) {// double
            return true;
        } else {
            return o instanceof Object[];
        }
    }
}

Related Tutorials