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 8020577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:43:47+00:00 2026-06-04T21:43:47+00:00

I am reading from a comma seperated file and splitting the contents into an

  • 0

I am reading from a comma seperated file and splitting the contents into an array. I am doing this in a while loop so I would want my arrays to have have a different name dynamically because the last line in the file end up overwriting my array content. Below is a fragment of my the code involved.

  TextView txt1;
  TextView txt2;

  Scanner in = new Scanner(result);
  in.nextLine(); //skip first line

  while(in.hasNextLine()){
    String line = in.nextLine();
    String []dataset = line.split(",");//store values in array

    txt1.setText(dataset[4]);//Should be 5th element of first line
    txt2.setText(dataset[4]);//Should be 5th element of second line
  }

As you can see from the above code I want to set the value of txt1 to a val in the first line of my file and similarly to the txt2. I read HashMaps or Maps or ArrayList would help me but I am not sure how to achieve this.

  • 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-04T21:43:48+00:00Added an answer on June 4, 2026 at 9:43 pm

    If I understand what you want to do correctly it is you want txt1 to equal the 5th element in the array on the 1st line and txt2 to have the text of the 5th element on the 2ed line (your comment says 3ed element but the code is pulling the 5th).

    This can be achieved with conditionals and a counter.

    Scanner in = new Scanner(result);
       in.nextLine(); //skip first line
       int count = 0;
       while(in.hasNextLine()){
    
          String line = in.nextLine();
          String []dataset = line.split(",");//store values in array
          if (count == 0){
              txt1.setText(dataset[4]);//Should be 3 element of first line
          }else if (count ==1){
              txt2.setText(dataset[4]);//Should be 3 element of second line
          }
        count++;
       }
      }
    

    EDIT:

    So now that I know you want an array of arrays the set up is easy. The outer array should be mutable if you dont know the amount of data you are processing before hand.

    ArrayList<String[]> dataSet = new ArrayList(10000)//number should be a guess at the amount of data
    Scanner in = new Scanner(result);
       in.nextLine(); //skip first line
       while(in.hasNextLine()){
    
          String line = in.nextLine();
          String []dataset = line.split(",");//store values in array
          dataSet.add(dataset);
       }
       txt1.setText(dataSet.get(0)[4]);
       txt2.setText(dataSet.get(1)[4]);
      }
    

    if you wanted to you could also create these text labels and store handels to them in a similar manner and set the text as you go.

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

Sidebar

Related Questions

I am reading data from a Comma-separated Value (CSV) document and saving its contents
I'm reading a comma-delimited list of strings from a config file. I need to
While reading from a configuration file in Perl there might be cases when a
I'm reading from a binary file and want to convert the bytes to US
I am reading a comma separated text file from the server, i get the
I have a comma seperated dataset called Book2.csv I want to extract the contents.
While reading from serial port I am using serialport.read(xyz,0,4) where xyz is a byte
I'm reading from a binary data file which is written by invoking the following
I am reading Earth quake Stats from a file and I need to be
While reading from a site a read that you can not make a global

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.