I have a variable of type Hashmap<String,Integer>.
In this, the Integer value might have to go some manipulation depending upon the value of a flag variable. I did it like this…
Hashmapvariable.put( somestring, if (flag_variable) { //manipulation code goes here new Integer(manipulated value); } else { new Integer(non-manipulated value); } );
But I get an error:
Syntax error on token(s), misplaced constructs.
at the Hashmapvariable.put call.
I also get another error
Syntax error on token ‘)’, delete this token.
at the final ‘);’ line. But I can’t delete the ‘)’ – its the closing parentheses for the put method call.
I don’t get this. What mistake am I doing?
You cannot place a statement in the method call.
However, one option could be to make an method that returns a
Integersuch as:Then, you can make a call like this: