Java implementation of the indexOf method
KW.java
class KW
{
    public static void main(String args[])
    {
        String s="Hello World",s1="World",s2="Hellz";
        System.out.println(s.indexOf('o'));
        System.out.println(s.indexOf('o',5));
        System.out.println(s.indexOf(s1));
        System.out.println(s.indexOf('z'));
        System.out.println(s.indexOf(s2));
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW 4 7 6 -1 -1 kodingwindow@kw:~$
Advertisement