String array to String - Java java.lang

Java examples for java.lang:String Array

Description

String array to String

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String[] elements = new String[] { "1", "abc", "level", null,
                "java2s.com", "asdf 123" };
        System.out.println(sats(elements));
    }/*from   ww w. ja  v a2 s  .co m*/

    /** String array to String */
    public static String sats(String[] elements) {
        String result = "";
        for (int i = 0; i < elements.length; i++) {
            result += elements[i];
            if (i + 1 < elements.length)
                result += " ";
        }
        return result;
    }
}

Related Tutorials