开发者

get value from particular index in java?

in one big grid array(like 500 rows,500 columns), i want to get the value开发者_开发知识库 by using index as (150th row,200th column).The condition is , i should not us one dimensional array,2 dimensional,3 dimensional for retrieving that values. i have no idea in hashmap?my colleague told to get the values from hashmap ?but i dont know how to pass the index and get the value?plz help me anyone??????


I'm not sure I completly understand your sentence, but thing is, you can use a single index to access the positions using something like an hashmap, if you make sure the keys you use for placing the values are unique.

For the hashmap example you mention, you just have to imagine of putting all the elements of your matrix (grid) in a line, meaning that for position i, j, in a single index x, it would be:

 index x = (max_line_length*(i-1))+j

where max_line_length = your_matrix.length

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜