File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes 2d Boolean Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "2d Boolean Array" Watch "2d Boolean Array" New topic

2d Boolean Array


Joined: Feb 09, 2005
Posts: 21
Fisrt of all forgive my ignorance, I'm only 5 weeks in on the language.
Im working on a 2d Boolean array that is represented as an imaginary floor, when moving my "rat" across the floor(also the name of the array), I need to be able to leave a trail if it is toggled by the user. almost all of the coding is done but I do not know how to return a Boolean value into a "floor space" as I travel across it can someone just give me a general idea of how to place a boolean value of true onto a 2d array that is already default as false? please do not give me the complete answer, just a gental kick in the right direction.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
array[x][y] = true; usually does the trick.

Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
Hi, Daniel -

If I understand what you're looking for, a simple assignment should do the trick. Because you capitalize Boolean, I'm assuming you are using Boolean objects, not primitive data types. You can't modify a Boolean object because the fields are final and there are no setter methods anyway. If you have an array of rows and objects, then you could create a new Boolean with the desired value and assign it to the array element you need to change.

Hope that helps...

Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
It would probably be easier to use the boolean primitive rather than the Boolean wrapper class. In such a case, an assignment will do the job of toggling the value.


Java API Documentation
The Java Tutorial
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
Very true, but if the professor wanted an array of Boolean objects and the student uses an array of boolean primitives, guess what the grade will be!
Don't get me started about those stupid light bulbs.
subject: 2d Boolean Array
jQuery in Action, 3rd edition