'Java equivalent for Oracle INSTR function

I need to write the Java equivalent for INSTR Oracle function.

Example in Oracle:

select INSTR('vivek Srinivasamoorthy','a',14) from DUAL

Output:15

How can I do this in Java?



Solution 1:[1]

String.indexOf() is your friend. Keep in mind that in Oracle counting start at 1, in Java at 0 (zero), so result in Java for your Oracle example will be 14. For docu see at Oracle DB server and Java.

In your specific case you can test it with System.out.println("is on index: " + "vivek Srinivasamoorthy".indexOf("a", 13));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1