|
-
removing a row from an array
I am working on an accounting system that calls for rows to be deleted out of arrays.
Say for instance that I know the indices of the row I wish to delete. How would I go about writing code to do this? I am trying to delete rows out of a 2D array.
Here's how I'm trying to go about this:
- create a copy of the 2D array
- copy the 2D array back into the original array, skipping the row that I don't want copied back (i.e. deleting the row)
The code below just makes the values in the cells to be deleted (the cells in the row to be deleted) all zeroes (the default values for the primitive type double), instead of actually getting rid of the row.
Look at the code below for what I'm talking about:
The code in the if block finds the row that I want to delete. I would use an easier method to do this, but my teacher wants it done this way.
LRRMasterArray = new double[LRRNumberofRows][]; // this needs to be LRRMasterArray = new double[LRRNumberofRows - 1][], but that doesn't compile for some reason
for (int row = 0; row < LRRdblTempArray.length; row++)
{
if (LRRdblTempArray[row][0] == LRRgetCustomerID())
{
LRRMasterArray[row] = new double[LRRdblTempArray[row].length];
} // end if
else
{
LRRMasterArray[row] = new double[LRRdblTempArray[row].length];
for (int col = 0; col < LRRMasterArray[row].length; col++)
{
LRRMasterArray[row][col] = LRRdblTempArray[row][col];
}
}
Thank you for reading this and any help from anyone would be greatly appreciated.
Similar Threads
-
By eruditionist in forum Java
Replies: 3
Last Post: 02-28-2006, 03:03 PM
-
By angelito in forum VB Classic
Replies: 1
Last Post: 11-21-2005, 06:16 AM
-
Replies: 6
Last Post: 11-01-2005, 09:05 AM
-
Replies: 2
Last Post: 07-01-2005, 12:03 PM
-
By kanakatam in forum Java
Replies: 2
Last Post: 04-15-2005, 09:06 PM
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