I am looking for methos similar to decode function in Oracle SQL. What I want to do is, int i =0; if (S.indexOf("P")= -1) i = 10000 else i = S.indexOf("P") I will like to do it in one line instead like, int i= decode(S.indexOf("P"),-1,10000) Is there any such method in any class that I can use here? Thanks!! [ July 31, 2002: Message edited by: Gemini Moses ]
Umm, can you not just write your own static method and put it in a utility class somewhere? If you can't do that, you could use the "ternary" or "query-colon" operator: int i = S.indexOf("P")==-1 ? 10000 : S.indexOf("P"); But note that this will call the (potentially slow) "indexOf" method twice, whereas: