Essentially, what I am trying to do is create a system that will take two inputs that references a row and a column of a grid, returning the value for that point. I am a very novice Java programmer, having moved to Java from Raptor. I know what I am looking to do with a long strand of if statements, however I want to avoid that. Essentially having an input refer to one of three columns, and another input refer to one of three rows, and the output being the point between them. I'm sorry for the lack of any coding, however I have no idea how I would even code it to begin with.
Asked
Active
Viewed 176 times
0
-
http://www.homeandlearn.co.uk/java/multi-dimensional_arrays.html – Daniel Stanley Nov 04 '14 at 16:56
1 Answers
0
You can use a 2 dimensional array, or hashmaps.
Syntax for creating a two-dimensional array
http://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html
http://www.tutorialspoint.com/java/java_hashmap_class.htm
Questions to ask yourself:
How many values? What operations are priority?
If the value set is small, and the time constraints on access are minor, then you can use either without any concerns.
The hash map memory footprint will be heavier, but you can use more complicated (arbitrary) keys.
Memory overhead of Java HashMap compared to ArrayList
For simplicity I would probably use the 2d array approach if it more closely models the structures you're creating.

Community
- 1
- 1

Nathaniel D. Waggoner
- 2,856
- 2
- 19
- 41