aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "what do this do?" Watch "what do this do?" New topic
Author

what do this do?

Chitlesh GOORAH
Greenhorn

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


Itx either one or zero_<br /><a href="http://spaces.msn.com/members/chitlesh" target="_blank" rel="nofollow">http://spaces.msn.com/members/chitlesh</a>
miguel lisboa
Ranch Hand

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

BTW what does this have to do with Swing?


java amateur
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

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
    
    6

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:



or:



Regards,
JD
[ May 26, 2005: Message edited by: John Dell'Oso ]
 
 
subject: what do this do?