aspose file tools
The moose likes Beginning Java and the fly likes the ? and : operators Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: the ? and : operators
 
Similar Threads
Bit-shift operators and primitive types
Is Java Pure Object Oriented?
need tips and tricks/link on shift parameters
Why didn't java support operator overloading
logic behind the shortcut operators