File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

? ... : 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.
Thanks!
Jason
[This message has been edited by jason adam (edited June 01, 2001).]
Marilyn de Queiroz
Sheriff

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

JavaBeginnersFaq
"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.
http://www.javaranch.com/ubb/Forum19/HTML/000179.html
[ February 06, 2003: Message edited by: Marilyn de Queiroz ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ? ... : operator