Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.List;

import java.util.Map;

public class Main {
    /**
     * For logging.
     *
     * @param map
     * @return
     */
    public static <K, V> String map2str(Map<K, V> map) {
        StringBuilder sb = new StringBuilder();
        try {
            if (!isEmpty(map)) {
                for (Map.Entry<K, V> entry : map.entrySet()) {
                    String key = entry.getKey().toString();
                    String val = entry.getValue().toString();
                    sb.append(key).append(':').append(val).append(',');
                }
                return sb.substring(0, sb.length() - 1);
            }
        } catch (Exception e) {
        }
        return sb.toString();
    }

    /**
     * Beware, the valid word "null" is also rendered as empty.
     *
     * @param str
     * @return
     */
    public static boolean isEmpty(String str) {
        return str == null || "".contentEquals(str) || "null".contentEquals(str);
    }

    public static <K, V> boolean isEmpty(Map<K, V> map) {
        return map == null || map.isEmpty();
    }

    public static <T> boolean isEmpty(List<T> l) {
        return l == null || l.isEmpty();
    }
}