Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;

import java.util.Collection;

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

public class Main {

    public static <K, V> List<K> keyToList(Map<K, V> map) {
        return keyToList(map, map.size());
    }

    public static <K, V> List<K> keyToList(Map<K, V> map, int count) {
        if (isNotNull(map)) {
            if (map.size() <= count) {
                return new ArrayList<K>(map.keySet());
            } else {
                List<K> list = new ArrayList<K>(map.keySet());
                return list.subList(0, count);
            }
        }
        return null;
    }

    public static boolean isNotNull(Object[] array) {
        return !isNull(array);
    }

    public static boolean isNotNull(Collection<?> con) {
        return !isNull(con);
    }

    public static boolean isNotNull(Map<?, ?> map) {
        return !isNull(map);
    }

    public static boolean isNull(Collection<?> con) {
        if (con == null || con.isEmpty()) {
            return true;
        }
        return false;
    }

    public static boolean isNull(Object[] array) {
        if (array == null || array.length == 0) {
            return true;
        }
        return false;
    }

    public static boolean isNull(Map<?, ?> map) {
        if (map == null || map.isEmpty()) {
            return true;
        }
        return false;
    }
}