Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class Main {
    public static final Map<String, String> map2Type(Map<String, Object> map) {
        Map<String, String> resultMap = new HashMap<String, String>();
        Iterator<String> iterator = map.keySet().iterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            Object value = map.get(key);
            resultMap.put(key, Object2String(value));
        }
        return resultMap;
    }

    public static final String Object2String(Object obj) {
        if (null == obj) {
            return "";
        } else if (obj instanceof String) {
            return (String) obj;
        } else if (obj instanceof Integer || obj instanceof Double || obj instanceof Float) {
            return String.valueOf(obj);
        } else if (obj instanceof String[]) {
            if (((String[]) obj).length > 0)
                return String.valueOf(((String[]) obj)[0]);
            else
                return "";
        } else if (obj instanceof List) {
            if (((List) obj).size() > 0)
                return String.valueOf(((List) obj).get(0));
            else
                return "";
        }
        return String.valueOf(obj);
    }
}