Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what do this do?

 
Chitlesh GOORAH
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
private int capacity;
capacity=(capacity != 0 ? 2*capacity:1 );
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its called the ternary operator
means:
if (this condition evaluates to true) doThis else doThat

BTW what does this have to do with Swing?
 
Joe Ess
Bartender
Posts: 9298
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java In General (Intermediate)
 
John Dell'Oso
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The line:



is shorthand (using the ternary operator) for:



or:



Regards,
JD
[ May 26, 2005: Message edited by: John Dell'Oso ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic