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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
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: 9190

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.

[How To Ask Questions On JavaRanch]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

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 ]
I agree. Here's the link:
subject: what do this do?
It's not a secret anymore!