What I am trying to do is make a program that reads a txt file and converts the number into a double array.

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class rocket {

    public static void main(String[] args) throws IOException, FileNotFoundException
    {
       System.out.println(readLines("/Users/Jeremy/Documents/workspace/altitude.txt"));
    }
    public static Double[] readLines(String filename) throws IOException {
        FileReader fileReader = new FileReader(filename);
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        List<Double> lines = new ArrayList<Double>();
        String line = null;
        while ((line = bufferedReader.readLine()) != null) {
            lines.add(Double.parseDouble(line));
        }
        bufferedReader.close();
        return lines.toArray(new Double[lines.size()]);
    }
}

This is my code, but when I run it I get [Ljava.lang.Double;@35960f05
A little info about my txt file, each number is on a seperateline and there is 26 numbers

[Ljava.lang.Double;@35960f05 is what you get when you call toString() on an array of Doubles (which is what println does when you print anything - it calls toString() to get a printable version). That toString method is inherited from Object.

There's a method in the Arrays class that converts arrays to the kind of string you want -
System.out.println(Arrays.toString(myArrayThatIWantToPrint));

Edited 3 Years Ago by JamesCherrill

Comments
That worked Thanks!

is there any particular reason ur keeping your readlines method static?

edit : didnt see that james already posted there....

Edited 3 Years Ago by somjit{}

This question has already been answered. Start a new discussion instead.