Skip to content

Commit 6042c95

Browse files
committed
feat: Use indexOf with starting index to locate substring in Java String
🔍 Functionality: - Finds the index of the substring `"udemy"` within `"www.udemy.com"` starting from index `4`. - Expected output: `4`, since `"udemy"` starts at position 4 in the string. 🧰 Method Used: - `String.indexOf(String str, int fromIndex)` — searches for the substring starting from the specified index and returns its first occurrence position. ✅ Purpose: To demonstrate how `indexOf()` can search from a specific position within a string. Signed-off-by: Somesh diwan <[email protected]>
1 parent 1ccb405 commit 6042c95

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
public class StringAB4 {
2-
public static void main(String[] args)
3-
{
2+
public static void main(String[] args) {
43
String str1 = "www.udemy.com";
54

65
System.out.println(str1.indexOf("udemy", 4));
76
}
8-
}
7+
}

0 commit comments

Comments
 (0)