-
Declaring an array help
I am writing a program that will have a input file that will have a person's name and id number information on the file. I have to make this file my array for my program b/c the user will type in either the name of the person and have the id# returned or the user will enter the id# and the name will be returned. The problem I am having trouble with is when setting up the array which will be a 2-D array how do i set the size of the array to the number of entries in the file? The reason why I want to do this is incase the number of records the file has increases or decreases.
-
ArrayList
Check out this one.
This should do just what you want, since it's an array you can extend dynamically. You need to extend your array dynamically since there is now way to know beforehahnd how many lines a file has. With the ArrayList, you can just add a new entry each time you read a line. Since the ArrayList takes Objects in the add method, you can add other arrays as well, thus creating the 2d array you want.
There are more then enough methods in there to do what you want, just check it out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks