Search code examples
javaarraysstringdoubleapache-commons-lang

Can't convert double array to String using Apache Commons Lang


I have been trying to convert a double array to a string where numbers are separated with a space.

public class StringTest {

    public static void main(String[] args) {

        double[] g =  {1.2,1.4,1.4} ;
        String d = StringUtils.join(g, " ");
        System.out.println(d);
    }
}

Commons Lang javadoc tells me that it is possible to do this, code runs as well but I get only [D@54a50a00 printed out. What is missing here?


Solution

  • You are currently using StringUtils#join(T...). You seem to want to use StringUtils#join(double[], char). Simply change your " " to a ' '.