Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.List;

public class Main {
    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);
    }
}