It's not a secret anymore!
The moose likes Cattle Drive and the fly likes ? ... : operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "? ... : operator" Watch "? ... : operator" New topic

? ... : operator

jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Is it frowned upon to use this operator for variable assignment? I've been looking through my 4b code, and have noticed several if/else statements that I use solely for the purpose of setting a String, and thought I could reduce the code a bit by using ?: instead of the whole if/else statement. While it compacts the code, I'm not sure if it is viewed as being less readable.
[This message has been edited by jason adam (edited June 01, 2001).]
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
Use of the ? ... : operator is acceptable.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Daniel Olson
Ranch Hand

Joined: Jan 05, 2001
Posts: 81
If you are interested here is a thread where we discussed using the ternary operator.
[ February 06, 2003: Message edited by: Marilyn de Queiroz ]
I agree. Here's the link:
subject: ? ... : operator
It's not a secret anymore!