File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes what do this do? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Java in General
Bookmark "what do this do?" Watch "what do this do?" New topic

what do this do?

Chitlesh GOORAH

Joined: May 07, 2005
Posts: 25
private int capacity;
capacity=(capacity != 0 ? 2*capacity:1 );

Itx either one or zero_<br /><a href="" target="_blank" rel="nofollow"></a>
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
its called the ternary operator
if (this condition evaluates to true) doThis else doThat

BTW what does this have to do with Swing?

java amateur
Joe Ess

Joined: Oct 29, 2001
Posts: 8915

It's the ternary conditional operator. It's covered in the Java Tutoral in the same page as if-then-else statements because it's shorthand for one.

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299

Moving to Java In General (Intermediate)

GenRocket - Experts at Building Test Data
John Dell'Oso
Ranch Hand

Joined: Apr 08, 2004
Posts: 130
The line:

is shorthand (using the ternary operator) for:


[ May 26, 2005: Message edited by: John Dell'Oso ]
GeeCON Prague 2014
subject: what do this do?