Search code examples
javaarrayslogicprimitive

Java syntax and logic help "?" and ":"


What does this line do? Mainly, I'm confused about the use of "?" and ":" and what they do (what are they called?).

Integer b1 = b.length > 0 ? b[0] : 0;

Apologies if the question is repeated I haven't been able to find anything related.


Solution

  • if b length is bigger than 0 it sets b1 to b[0] else it sets b1 to 0