in java, which is better - three arrays of booleans or 1 array of bytes?

Posted by joe_shmoe on Stack Overflow See other posts from Stack Overflow or by joe_shmoe
Published on 2010-04-12T15:50:41Z Indexed on 2010/04/12 15:53 UTC
Read the original article Hit count: 229

I know the question sounds silly, but consider this: I have an array of items and a labelling algorithm. at any point the item is in one of three states. The current version holds these states in a byte array, where 0, 1 and 2 represent the three states. alternatively, I could have three arrays of boolean - one for each state. which is better (consumes less memory) depends on how jvm (sun's version) stores the arrays - is a boolean represented by 1 bit? (p.s. don't start with all that "this is not the way OO/Java works" - I know, but here performance comes in front. plus the algorithm is simple and perfectly readable even in such form).

Thanks a lot

© Stack Overflow or respective owner

Related posts about java

Related posts about arrays