String str = "Hello, World!"; int index = str.indexOf(","); System.out.println(index);
String str = "The quick brown fox jumps over the lazy dog"; int index = str.indexOf("fox"); System.out.println(index);In this case, the `indexOf()` method is used to find the index of the substring `fox` within the `str` string. The output of this code would be `16`, since `fox` begins at the 17th character in the string. The `indexOf()` method is part of the core Java library, specifically the `java.lang` package.