Results 1 to 7 of 7
- 02-12-2013, 06:02 AM #1
Member
- Join Date
- Feb 2013
- Location
- San Diego
- Posts
- 63
- Rep Power
- 0
Multiple int arrays or one String array?
I have a program in which I need to keep track of what squares of a grid are occupied by what. The grid itself is an array of JLabels 10 rows by 20 columns (unnessecary information). I need to keep track of which squares are occupied by what type of thing, and which of those things it is occupied by. I could use one String array [10][20] with values "(type of thing)"+(number) or multiple int arrays [10][20] with value (number) and the type of thing as the name of the array. If I do that, should I make one more boolean array for ease of use in methods (all the things would cause the same basic actions) or just mention all arrays in the methods?
Sorry if its confusing or unclear. I'm about to slumber but was pondering this and I resolved to ask someone else's opinion.Last edited by Prime624; 02-12-2013 at 03:29 PM.
- 02-12-2013, 08:10 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
Re: Multiple int arrays or one String array?
Don't encode the type information and other stuff in a String; also don't use two arrays that are logically 'tied together'; both options are clumsy at best. Create a small class for that purpose and have a single array of objects of that class.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-12-2013, 03:40 PM #3
Member
- Join Date
- Feb 2013
- Location
- San Diego
- Posts
- 63
- Rep Power
- 0
Re: Multiple int arrays or one String array?
I understand why not to use a String array, as I've already had some trouble with them, but why shouldn't I semi-link them? It would just be a [10][20] boolean array. True for anything there and false for nothing there.
- 02-12-2013, 03:44 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
Re: Multiple int arrays or one String array?
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-12-2013, 06:25 PM #5
Member
- Join Date
- Feb 2013
- Location
- San Diego
- Posts
- 63
- Rep Power
- 0
Re: Multiple int arrays or one String array?
Just to say "if this array[y][x] or this array[y][x] then boolean array[y][x] is true."
- 02-12-2013, 07:25 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
Re: Multiple int arrays or one String array?
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-12-2013, 07:28 PM #7
Member
- Join Date
- Feb 2013
- Location
- San Diego
- Posts
- 63
- Rep Power
- 0
Similar Threads
-
Printing multiple arrays help...
By Toffer_15 in forum New To JavaReplies: 8Last Post: 01-24-2013, 09:35 PM -
Printing multiple arrays in 1 dialog box
By turbopenguin in forum New To JavaReplies: 9Last Post: 04-19-2012, 08:18 AM -
Storing Multiple 2d Arrays in a file.
By onifiro in forum New To JavaReplies: 1Last Post: 01-11-2011, 12:39 AM -
Sorting Multiple Parallel Arrays
By Pyrexkidd in forum New To JavaReplies: 7Last Post: 05-12-2010, 06:34 AM -
store array of arrays in array of arrays
By joost_m in forum New To JavaReplies: 4Last Post: 04-19-2010, 10:32 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks