aspose file tools*
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
Author

Pass file into 2d array

Bob Holly
Greenhorn

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

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?
Bob


Bob
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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]
 
 
subject: Pass file into 2d array