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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:23:10+00:00 2026-06-15T16:23:10+00:00

I try to readout a csv-File. In my Code I readout the Lines in

  • 0

I try to readout a csv-File. In my Code I readout the Lines in the csv-File. Therefor I use an arraylist to add each item in the line to the arraylist.

After reading out a line i storte the array list in an other array list and then go to read out the next line and so on and ao on.

Now I have here a few Questions and one Problem.

1) When I add an item to an arraylist is it always added at the en of the list (When I give no specific place where to add the item like in my code)? With this then the order of the csv-file would be keeped.

2) I figuered out, that when I clear the arraylist datatemp to prepare the reading of the next line, also the content of the array list data is cleared. How can I prevent my code from doing so?

3) Is there a way to make an normal array out of the arraylist data I have?

4) Is my way of reading out the csv-File correct or is there any better way?

public class CSVReader {    

public void ReadCSV (String csvfilepath) {

    BufferedReader CSVFile = null;
    String dataRow = null;
    ArrayList<Float> datatemp = new ArrayList<Float>(); 
    ArrayList<ArrayList<Float>> data = new ArrayList<ArrayList<Float>>(); 

    try {
        CSVFile = new BufferedReader(new FileReader(csvfilepath));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    try {
        dataRow = CSVFile.readLine();
    } catch (IOException e) {
        e.printStackTrace();
    }

    while (dataRow != null){
        String[] dataArray = dataRow.split(",");
        for (String item:dataArray) {
            datatemp.add(Float.valueOf(item));
        }
        try {
            dataRow = CSVFile.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }

        data.add(datatemp);
        datatemp.clear();
    }

    try {
        CSVFile.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    }
} 
  • 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-15T16:23:12+00:00Added an answer on June 15, 2026 at 4:23 pm

    1) With this then the order of the csv-file would be keeped.

    Yes

    2) How can I prevent my code from doing so?

    You need to create a new tempArrayList each time:

    while (dataRow != null){
        datatemp = new ArrayList<Float>();
    

    3) Is there a way to make an normal array out of the arraylist data I have?

    You can create an array of arraylists:

    ArrayList[] array = data.toArray(new  ArrayList[data.size()]);
    

    You can do then it recursively to create a 2D array, but I would stick to the list of list which is easier to handle.

    4) Is my way of reading out the csv-File correct or is there any better way?

    Use a library, there are many of them, which has been tested. It is much more difficult to parse a CSV file correctly than it seems at first sight.

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

Sidebar

Related Questions

Possible Duplicate: HTTP_ACCEPT_LANGUAGE i try to code a language option tool. therefor i use
I try to build a crawler or a atuomatic downloader for each file is
I try to read out a table and write it into a csv file.
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
try { // Create an appending file handler boolean append = true; FileHandler handler
Try running the following code: class Test(object): def func_accepting_args(self,prop,*args): msg = %s getter/setter got
I have simple code with intent to return enumerator over a file or a
Try running the code below: <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js></script> <script> b = jQuery.noConflict(true); </script> <script src=http://ajax.googleapis.com/ajax/libs/mootools/1.2.3/mootools-yui-compressed.js></script>
Try to work with Amazon Product API. Lot of code work, but have a

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.