Check out example codes for "indexof in java". It will help you in understanding the concepts better.

Code Example 1

public class MyClass {
  public static void main(String[] args) {
    String myStr = "Hello planet earth, you are a great planet.";

Code Example 2

  // Initialising String 
        String gfg = new String("Welcome to geeksforgeeks"); 
        System.out.print("Found g first at position : "); 
        // Initial index of 'g' will print 
        // prints 11 

Code Example 3

The java string indexOf() method returns index of given character value or substring. If it is not found, it returns -1. The index counter starts from zero.

Learn ReactJs, React Native from