looking for alternitive to passing an associative array in JSP
I'm using JSP where the user selects a background. The number of times each past selection has been made will be recorded. Example: green was used twice, yellow was used once, red was used five times. I wanted to use an associative array where the colour is the key and the value is the number of times it was used. But Java doesn't 开发者_如何学Gohave associative arrays so I guess my next best option is a normal array?
Also, how do I pass this information from one page to the next? I was thinking of using hidden fields but that wouldn't work with an array.
As Bozho said, use a HashMap<Color, Integer>
. For updating the count you'd have to get the integer from the map, increment and put it back to the map.
Also, how do I pass this information from one page to the next?
You might store that map in the user's session.
Java has HashMap
, which is exactly an associative array - you have a key of any type (may be string) and a value of any type, with lookup O(1)
精彩评论