This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes the ? and : operators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "the ? and : operators" Watch "the ? and : operators" New topic

the ? and : operators

Gaia Nathan
Ranch Hand

Joined: Aug 01, 2001
Posts: 62
Can someone tell me what the ? and : operators do?
I can't find a reference to them.
Sunetra Saha
Ranch Hand

Joined: Feb 25, 2001
Posts: 77
they make up a consolidated if-else syntax.
You can write the following if statement
{ statementA;
}else statementB;
Kaspar Dahlqvist
Ranch Hand

Joined: Jun 18, 2001
Posts: 128
Actually, the ? : is called the Conditional Operator. Some code to illustrate what Sunetra wrote:

Hope this helps!
Gaia Nathan
Ranch Hand

Joined: Aug 01, 2001
Posts: 62
Thanks Sunetra, Kaspar. Both your replies made it very clear for me.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: the ? and : operators
Similar Threads
need tips and tricks/link on shift parameters
logic behind the shortcut operators
Bit-shift operators and primitive types
Is Java Pure Object Oriented?
Why didn't java support operator overloading