Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.IOException;
import java.io.InputStream;

import java.util.ArrayList;

public class Main {

    public static String listToString(ArrayList<String> list, String flag) {
        String strMsg = "";
        int listSize = list.size();
        if (listSize > 0) {
            for (int i = 0; i < listSize; i++) {
                if (i == listSize - 1) {
                    strMsg = strMsg + list.get(i).toString();
                } else {
                    strMsg = strMsg + list.get(i).toString() + flag;
                }
            }
        } else {
            strMsg = "";
        }
        return strMsg;
    }

    public static String toString(InputStream in) throws IOException {
        StringBuffer out = new StringBuffer();
        byte[] buffer = new byte[1024];
        for (int i; (i = in.read(buffer)) != -1;) {
            out.append(new String(buffer, 0, i));
        }
        return out.toString();
    }
}