0

Question is kind of hard to ask. I'll try my best to explain it.

I have a 2D array that is a grid. This grid has its contents filled with 0 and 1.

I want to store in a list the coordinates of the array that only have 0. How would you do that?

For example: the coordinate location 2, 3 has the value of 0. How should one go about storing the 2, 3?

3
  • by "list" do you mean a java.util.List, or a one-dimensional array? Commented Apr 18, 2011 at 1:41
  • @jcomeau_ictx Would the answer be different either way? Commented Apr 18, 2011 at 1:45
  • just trying to get a clearer question. and yes, slightly. Commented Apr 18, 2011 at 1:47

1 Answer 1

5

Create a Point class that has coordinates (x,y) and the value 0 or 1. Store a List<Point> and you're all set.

Sign up to request clarification or add additional context in comments.

3 Comments

THANK YOU, wow I feel stupid. I've been using point all this time and didn't realize I should do it that way...
As a side note, I find that having a Map<Point,SomeValue> works a lot better than a SomeValue[]. Three reasons: 1) Separation from 0. 2) Negative coords. 3) Non-rectangular grids (Think shaped like Utah) don't waste tons of space.
@abc123 If duffymo's reply answered your question, please mark it correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.