This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 9044
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 ]
jQuery in Action, 2nd edition
subject: ? ... : operator
Similar Threads
Ternary operator with if/elseif/else
Where is Wrapper class toString method? (To ARS Kumar)
How do you translate this : ?
Compiling a Java file using Java
error message