2Darray to 1darray with for loop


I know this is a very basic question, but I'm just new to programming and I think I'am struggling with a very simple issue... but here we go :p

In my app I have an array of arrays like this storing data retrieved from a mysql database.

data_array[][] 0001 | data1 | data2 | data3 | data4 | data5 0002 | data1 | data2 | data3 | data4 | data5 ... ... and so on.

Now in my app, I need to retrieve for each of the rows the first of the colums, ending with something like :

array { 0001, 0002}

I know doing ' for iterations ' I can retrieve all the data:

public String[] itarray{ int cols = 5; String[] xFINAL; for (int i=0 ; i < data_array; i++) { for (int j=0; j < cols; j++){ xFINAL = data_array[i]; System.out.println("1" + data_array[i][0]); } System.out.println(" "); } return xFINAL;}

But how can I get the first column for each of the rows? I tried with something like:

int j=0; for (int i = 0; i < data_array ; i++){ xFINAL[j] = data_array [i][0]; j++; }

But it's giving me a null pointer. How could I do this please?

Thanks in advance.


String[] xFINAL = new String[data_array.length]; int k =0; for (int i=0 ; i < data_array; i++) { array[k++] = data_array[i][0]; }


  • Android ArrayAdapter notifyDataSetChanged doesn't work
  • Getting “Error: #28: expression must have a constant value ” while using varidic macro
  • Is this a safe way for inserting and updating an array of objects in mongodb?
  • Allocating dynamic array of struct on C.
  • Error in bind_rows_(x, .id) : Column can't be converted from factor to numeric
  • Multiple ggAcf plot in R
  • Clustering transactional data using PAM in R?
  • ASP.NET MVC 2 - ViewData empty after POST
  • How to get google charts X-Axis points starting at the left most point
  • Dealing with Split() function: how to adjust for either return/tab input
  • Bash Append header information to each line of a file until next header found
  • Stringlist and CSV
  • Is the memory allocated by new operated consecutive?
  • Merge multiple dataframe pandas
  • Google chart horizontal scrollbar
  • Map which allows duplicate key as well as maintain insertion order
  • In PHP, are objects methods code duplicated or shared between instances?
  • Spark sorting of delimited data
  • How can I prevent a double submit($.post) with jQuery
  • How to get data from URL using Windows and C?
  • Merge Command in R
  • Python Multiple file writing question
  • Interpret strings as packed binary data in C++
  • Create CSV file from c#: extra character in excel
  • Save and retrieve an image file in LibGDX
  • Insert records into two table at once
  • Sql indexes vs full table scan
  • PDO error when wrong host name
  • MYSQ & MVC3 SQL connection error \\ ProviderManifestToken but I am using MySQL
  • HTTP/2 streams vs HTTP/1.1 connections
  • Moving mysql files across servers
  • How to extract text from Word files using C#?
  • How to check if every primary key value is being referenced as foreign key in another table
  • Sending data from AppleScript to FileMaker records
  • Comma separated Values
  • trying to dynamically update Highchart column chart but series undefined
  • embed rChart in Markdown
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app