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

Recommended Answers

[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 …

Jump to Post

All 3 Replies

Re: Read and convert to a double array 80 80

[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));

commented: That worked Thanks! +2
Re: Read and convert to a double array 80 80

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

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

Re: Read and convert to a double array 80 80

There isn't a reason for the static and that worked thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.