Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Collection;

import java.util.Map;

public class Main {

    public static Class<?> findCommonElementType(Collection collection) {
        if (isEmpty(collection))
            return null;
        Class<?> candidate = null;
        for (Object val : collection) {
            if (val != null) {
                if (candidate == null)
                    candidate = val.getClass();
                else if (candidate != val.getClass())
                    return null;
            }
        }
        return candidate;
    }

    public static boolean isEmpty(Collection collection) {
        return collection == null || collection.isEmpty();
    }

    public static boolean isEmpty(Map map) {
        return map == null || map.isEmpty();
    }
}