How to Find a String in a String in Java


In this example, we will learn the method to find a string in a string in Java.

Source Code

package com.beginner.examples;

public class FindString {
  public static void main(String[] args) {
    String str = "You 'are' right.";
    System.out.println(str.indexOf("are")); // find a string in a string
  }
}

Output:

5
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments