Double array to String - Java java.lang

Java examples for java.lang:String Array

Description

Double array to String

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        double[] elements = new double[] { 34.45, 35.45, 36.67, 37.78,
                37.0000, 37.1234, 67.2344, 68.34534, 69.87700 };
        System.out.println(dats(elements));
    }//from  ww w .j a v  a 2  s . c  o m

    /** Double array to String */
    public static String dats(double[] elements) {
        String[] data = new String[elements.length];
        for (int i = 0; i < elements.length; i++) {
            data[i] = elements[i] + "";
        }
        return sats(data);
    }

    /** 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