Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By JosAH

Thread: Multiple int arrays or one String array?

  1. #1
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default 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.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,304
    Blog Entries
    7
    Rep Power
    20

    Default 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,

    Jos
    DarrylBurke likes this.
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default 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.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,304
    Blog Entries
    7
    Rep Power
    20

    Default Re: Multiple int arrays or one String array?

    Quote Originally Posted by Prime624 View Post
    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.
    Why should you 'link' them? There'd be nothing in the code that prevents you from ruining the two arrays so that the 'link' doesn't make sense anymore.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default 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."

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,304
    Blog Entries
    7
    Rep Power
    20

    Default Re: Multiple int arrays or one String array?

    Quote Originally Posted by Prime624 View Post
    Just to say "if this array[y][x] or this array[y][x] then boolean array[y][x] is true."
    So you have a situation where C= f(A, B) whatever f and A and B may be; also f( ... ) can be calculated in O(1) (i.e. "one simple step"); so you don't need C at all, just use f(A, B)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default Re: Multiple int arrays or one String array?

    Thank you for your help.

Similar Threads

  1. Printing multiple arrays help...
    By Toffer_15 in forum New To Java
    Replies: 8
    Last Post: 01-24-2013, 09:35 PM
  2. Printing multiple arrays in 1 dialog box
    By turbopenguin in forum New To Java
    Replies: 9
    Last Post: 04-19-2012, 08:18 AM
  3. Storing Multiple 2d Arrays in a file.
    By onifiro in forum New To Java
    Replies: 1
    Last Post: 01-11-2011, 12:39 AM
  4. Sorting Multiple Parallel Arrays
    By Pyrexkidd in forum New To Java
    Replies: 7
    Last Post: 05-12-2010, 06:34 AM
  5. store array of arrays in array of arrays
    By joost_m in forum New To Java
    Replies: 4
    Last Post: 04-19-2010, 10:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •