I am new to Java programing, and I am confused when using the String.IndexOf(int ch) in my code.
For example, I want to find the first occurrence of '-' in a string "abc-def-ghi".
so here is my code:
String test = "abc-def-ghi";
int firstOcc = test.IndexOf('-');
This code is working fine.
However, my question is, why String.IndexOf() function takes a int parameter as a char?
Is there any benefit to writing code as IndexOf(int ch) instead of IndexOf(char ch)?
Thanks for any help!
String.indexOf(int). OP is asking why the arg isintand notchar.