File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Pass file into 2d array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Pass file into 2d array" Watch "Pass file into 2d array" New topic

Pass file into 2d array

Bob Holly

Joined: Jul 27, 2006
Posts: 1
Im new to this and 2d arrays, now i know how to hard code arrays.
String[][] teamMemberNames = { { "Joe", "Mary", "Allison", "Brian", "Jack" },
{ "Harry", "Pete", "Sam", "Maria", "William", "George", "Dan" }}

But now i want to pass a file into an 2darray and display the array to screen.
I read in a csv file using file reader and bufferedreader and then readline() to pass it into a ArrayList of strings.

Normally id convert array list of strings into a string array, use the split() to seperate commas and print the file to a table, but i dont know how to pass a arraylist to a 2darray or use split() in a 2darray.

Any advice?

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Hi Bob,

Welcome to JavaRanch!

A Java 2D array is actually just an array of 1D arrays; i.e.,

So to build your 2D array, you just allocate the "backbone" and then just fill in the lines. If you don't know the size of the "backbone" until you've created all the lines, then store the lines in a java.util.ArrayList until you've created them all, then use the toArray() method to create the 2D array.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Pass file into 2d array
It's not a secret anymore!