aspose file tools*
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "the ? and : operators" Watch "the ? and : operators" New topic
Author

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
if(condA)
{ statementA;
}else statementB;
as
condA?statementA:statementB
Kaspar Dahlqvist
Ranch Hand

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

Hope this helps!
//Kaspar
Gaia Nathan
Ranch Hand

Joined: Aug 01, 2001
Posts: 62
Thanks Sunetra, Kaspar. Both your replies made it very clear for me.
 
 
subject: the ? and : operators