Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9028573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:01:06+00:00 2026-06-16T07:01:06+00:00

What I need to achieve is to import data from a text file that

  • 0

What I need to achieve is to import data from a text file that contains two columns of doubles as follows:

201.0176    1.06E+03
201.7557    1.11E+01
202.0201    2.02E+02
202.2064    9.76E+00
202.8342    1.11E+01
203.0161    2.02E+02
203.1638    9.61E+00
203.3843    1.13E+01

There are up to about 50,000 lines of these data. I want each column to be imported into a separate array but I cannot work out how to identify between the separate columns. I have tried the following:

public class CodeTests {

    public static ArrayList assignArray(String filePath) throws FileNotFoundException {
        Scanner s = new Scanner(new File(filePath));
            ArrayList<Double> list = new ArrayList<Double>();
            while (s.hasNext()){
                list.add(s.nextDouble());
            }
            s.close();
            return list;
    }

    public static void main(String[] args) throws IOException {
        /*
         * 
         */
        ArrayList arrayMZ;
        arrayMZ = assignArray("F:/Stuff/Work/Work from GSK/From Leeds/ja_CIDFragmenter/testFile.txt");

        for(int i = 0; i < arrayMZ.size(); i++)
            System.out.println(arrayMZ.get(i));
        System.out.println("End");
    }
}

From running this I get the output:

run:
201.0176
1060.0
201.7557
11.1
202.0201
202.0
202.2064
9.76
202.8342
11.1
203.0161
202.0
203.1638
9.61
203.3843
11.3
End
BUILD SUCCESSFUL (total time: 1 second)

Can anyone help me either separate these columns into two arrays or even into a single 2D array under the columns of array[0] with the first data column in it and array[1] with the second. i.e. :

  [0]         [1]
201.0176    1.06E+03
201.7557    1.11E+01
202.0201    2.02E+02
202.2064    9.76E+00
202.8342    1.11E+01
203.0161    2.02E+02
203.1638    9.61E+00
203.3843    1.13E+01

I’ve tried to make this as clear as I can but if there is anything else please let me know.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:01:08+00:00Added an answer on June 16, 2026 at 7:01 am

    You could do something like this:

    public static ArrayList[] assignArray(String filePath) throws FileNotFoundException {
        Scanner s = new Scanner(new File(filePath));
            ArrayList[] list = new ArrayList[2];
            ArrayList<Double> col1 = new ArrayList<Double>();
            ArrayList<Double> col2 = new ArrayList<Double>();
            while (s.hasNext()){
                String[] data = s.nextLine().split("\\s+"); 
                col1.add(Double.parseDouble(data[0]));
                col2.add(Double.parseDouble(data[1]));
            }
            s.close();
            list[0] = col1;
            list[1] = col2;
            return list;
    }
    

    and obtain an array of two ArrayList with your data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to make an excel file which would fetch data from connection to
I need to achieve layout like shown on my sketch. Multiple columns - user
$(#mute).click(function(){ $(#audioplayer)[0].muted = $(#audioplayer)[0].muted; $(#message).text(Volume muted); }) What I need to achieve is when
Two things I'm trying to achieve and need help with 1) Click a link
That's what I wanna achieve : There will be dll which contains only methods
I need some text data (street names of a 2 million town) to get
In my app I sometimes need to import some CSV data and I wanna
I need to achieve some kind of extensibility for a custom project template. Having
I need to achieve something like a folder view in Springboard, when you press
I need to achieve the following query - tags is an internal array in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.