is Empty Array - Java Collection Framework

Java examples for Collection Framework:Array Element

Description

is Empty Array

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        Object result = "java2s.com";
        System.out.println(isEmptyArray(result));
    }//from w  w w  . j  a  v  a 2  s .  c om

    public static boolean isEmptyArray(Object result) {
        if (result.getClass().isArray()) {
            if (result instanceof byte[]) {
                return (((byte[]) result).length == 0);
            } else if (result instanceof short[]) {
                return (((short[]) result).length == 0);
            } else if (result instanceof int[]) {
                return (((int[]) result).length == 0);
            } else if (result instanceof long[]) {
                return (((long[]) result).length == 0);
            } else if (result instanceof float[]) {
                return (((float[]) result).length == 0);
            } else if (result instanceof double[]) {
                return (((double[]) result).length == 0);
            } else if (result instanceof char[]) {
                return (((char[]) result).length == 0);
            } else if (result instanceof boolean[]) {
                return (((boolean[]) result).length == 0);
            } else {
                //result instanceof Object[]
                return (((Object[]) result).length == 0);
            }
        }

        return false;
    }
}

Related Tutorials