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

  • Home
  • SEARCH
  • 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 8447713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:14:55+00:00 2026-06-10T10:14:55+00:00

I am using the following code to read in a CSV file: String next[]

  • 0

I am using the following code to read in a CSV file:

  String next[] = {};
  List<String[]> dataArray = new ArrayList<String[]>();

  try {
      CSVReader reader = new CSVReader(new InputStreamReader(getAssets().open("inputFile.csv")));
      for(;;) {
          next = reader.readNext();
          if(next != null) {
              dataArray.add(next);
          } else {
              break;
          }
      }
  } catch (IOException e) {
      e.printStackTrace();
  }

This turns a CSV file into the array ‘dataArray’. My application is for a dictionary type app – the input data’s first column is a list of words, and the second column is the definitions of those words. Here is an example of the array loaded in:

Term 1, Definition 1
Term 2, Definition 2
Term 3, Definition 3

In order to access one of the strings in the array, I use the following code:

dataArray.get(rowNumber)[columnNumber]

However, I need to be able to generate a list of all the terms, so that they can be displayed for the dictionary application. As I understand it, accessing the columns by themselves is a much more lengthy process than accessing the rows (I come from a MATLAB background, where this would be simple).

It seems that in order to have ready access to any row of my input data, I would be better off transposing the data and reading it in that way; i.e.:

Term 1, Term 2, Term3
Definition 1, Definition 2, Definition 3

Of course, I could just provide a CSV file that is transposed in the first place – but Excel or OO Calc don’t allow more than 256 rows, and my dictionary contains around 2000 terms.

Any of the following solutions would be welcomed:

  • A way to transpose an array once it has been read in
  • An alteration to the code posted above, such that it reads in data in the ‘transposed’ way
  • A simple way to read an entire column of an array as a whole
  • 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-10T10:14:57+00:00Added an answer on June 10, 2026 at 10:14 am

    You would probably be better served by using a Map data structure (e.g. HashMap):

    String next[] = {};
    HashMap<String, String> dataMap = new HashMap<String, String>();
    
    try {
        CSVReader reader = new CSVReader(new InputStreamReader(getAssets().open("inputFile.csv")));
        for(;;) {
            next = reader.readNext();
            if(next != null) {
                dataMap.put(next[0], next[1]);
            } else {
                break;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    

    Then you can access the first column by

    dataMap.keySet();
    

    and the second column by

    dataMap.values();
    

    Note one assumption here: that the first column of your input data is all unique values (that is, there are not repeated values in the “Term” column).

    To be able to access the keys (terms) as an array, you can simply do as follows:

    String[] terms = new String[dataMap.keySet().size()];
    terms = dataMap.keySet().toArray(terms);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to read the content of a PDF file: string
When I using the following code to read file: lines=file(data.txt).read().split(\n) I have the following
Using following code I try to get updated list of checkbuttons' corresponding text values,
I am creating date using following code try { newdatetime = new DateTime(2012, 2,
I'm using the following code to read a local text file from a local
for my application i have to parse CSV file using Erlang.following is the code
I'm using the following code to read a map of type HashMap<String, String >
I'm using the following code to read an XML file - var xmlhttp; if
I am using IExcelDataReader to reader to read a excel sheet using following code:
I am using following code to read a sub-sequence from a file. FileChannel channel

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.