Help with hashmap
Hello all,
Each title has a bunch of question. Those questions should have numbering to be displayed.
I am trying to find out how I can use a HashMap to do this.
HashMap quesAnsHash =new HashMap();
forEach title, i want to use something like this
quesAnsHash.put(question,new Integer(1));// This integer should increment for each question within the title.
I need to increment this integer for subsequent questions for the same title
and I need help to display them too..
Please let me know how I can do this. Hopefully, I question is conveyed properly.
Thanks
[723 byte] By [
gradnasha] at [2007-11-27 0:44:52]

# 1
For a HashMap, the correct syntax for the put method is put(key, value)you have it reversed.Create a loop and within the loop execute the put method.Replace new Integer(1) with a variable parameter that is increased by one each time throught the loop.
# 2
> Replace new Integer(1) with a variable
> parameter that is increased by one each time throught
> the loop.
In Java 1.4, rather replace just 1 with the variable indicating the next number. Until you move to Java 1.5, you still need new Integer(yourVariable) before passing to HashMap.put().
OleVVa at 2007-7-11 23:09:29 >

# 4
> > you still need new
> > Integer(yourVariable) before passing to
> > HashMap.put().
>
> Not if the variable is an Integer.
If the variable is an Integer, in Java 1.4, how would you increase it by 1 each time through the loop?
Yes, I know you could write something like
yourVariable = new Integer(yourVariable.intValue() + 1);
I think my suggestion was simpler and therefore, better.
OleVVa at 2007-7-11 23:09:29 >
