Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.util.List;

public class Main {

    public static String list2String(List<?> list) {
        return array2String(list2Array(list));
    }

    public static <T> String array2String(T... array) {
        int len = array.length;
        if (len == 0) {
            return "";
        }

        StringBuilder sb = new StringBuilder();
        sb.append("[").append(array[0]);
        for (int i = 1; i < array.length; i++) {
            sb.append(",").append(array[i]);
        }
        sb.append("]");

        return sb.toString();
    }

    /**
     * Convert List to array
     * 
     * Example:
     *     String[] myarray = (String[]) ArrayUtil.list2Array(mylist);
     * 
     * @param list
     * @return
     */
    public static <T> Object[] list2Array(List<T> list) {
        return list.toArray();
    }
}