What is a Question Mark “?” and Colon “:” Operator Used for?

This is the ternary conditional operator, which can be used anywhere, not just the print statement. It’s sometimes just called “the ternary operator”, but it’s not the only ternary operator, just the most common one. Here’s a good example from Wikipedia demonstrating how it works: A traditional if-else construct in C, Java and JavaScript is written: This … Read more

What is the Java ?: operator called and what does it do?

Yes, it is a shorthand form of It’s called the conditional operator. Many people (erroneously) call it the ternary operator, because it’s the only ternary (three-argument) operator in Java, C, C++, and probably many other languages. But theoretically there could be another ternary operator, whereas there can only be one conditional operator. The official name is given in the Java Language … Read more