I'm writing a program in Java that needs to make use of the four cardinal directions (North, East, South, and West). The problem I keep running into is how to represent each direction such that I use as little memory as possible. At first one would think that you can use a String to represent each direction as "North", "East", "South", and "West", but String comparisons are wasteful and not really necessary when all I have are four values I want to compare between. Not to even mention, the strings alone use a good chunk of memory beyond the scope of this problem.
I came up across the idea of using a boolean[] of length 2. There are only four possible combinations (00, 01, 10, and 11) which I could map to each direction. The problem I came across is that the boolean array will not use the two bits of space I expected it to in the memory. According to this answer: SO post, the array could take up to 4 additional Bytes of memory. Not really what I'm looking for...
After doing some more searching many posts and sites suggested the BitSet() object, but again, according to the post above, an object in java can take between 8 to 16 bytes of memory. Would anyone know how to best approach this problem in terms of keeping memory usage low? Preferably I would only like to use those two bits for representing the cardinal directions.
Is there really no way to represent (in Java) something like these four cardinal directions with exactly two bits? If not, what would be the most memory efficient representation of the cardinal directions for such a program?