Find the Index of First Occurrence of a Substring in a String using Java

indexOf method

package app;

public class Main
{
    public static void main(String[] args)
    {
        String text = "123 456 56 78";
        int idx = text.indexOf("56");

        System.out.println(idx); // 5
    }
}

Leave a Comment

Cancel reply

Your email address will not be published.