java - Ternary operator usages? -


i know ternary operator used of doing variable assignment after evaluating logical condition.

so:

string s = (logicalvariable) ? "hello" : "bye, bye"; 

or,

int x = (5<3) ? 10 : 100; 

would usage examples, right?

but if idon't want variable assignment set sentence or piece of code, example:

if (inventario.containskey(item))         return inventario.get(item);     else return integer.min_value; 

can these lines writen in one line expression, using ternary operator?

this should work:

return inventario.containskey(item)? inventario.get(item); integer.min_value; 

the first part need evaluate boolean


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -