Join Lines of string to string - Android java.lang

Android examples for java.lang:String Join

Description

Join Lines of string to string

Demo Code

import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.net.Uri;
import android.util.Log;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{

    public static String JoinLines(List<String> list) {
        StringBuilder sb = new StringBuilder();
        boolean first = true;

        for (String line : list) {
            if (first) {
                first = false;/*ww w . j  a  v  a 2s .  c om*/
            } else {
                sb.append("\n");
            }
            sb.append(line);
        }

        return sb.toString();
    }

}

Related Tutorials