aspose file tools
The moose likes Beginning Java and the fly likes Method similar to decode function in Oracle SQL Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Method similar to decode function in Oracle SQL" Watch "Method similar to decode function in Oracle SQL" New topic
Author

Method similar to decode function in Oracle SQL

Gemini Moses
Ranch Hand

Joined: Jan 04, 2001
Posts: 244
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 ]
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6919
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:

will only call it once.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Method similar to decode function in Oracle SQL
 
Similar Threads
Can I Select column A OR column B ?
Date difference, with the table containing null values for date
decode in db2
String searching
Strange IBatis Exception. Plz Help!!