Commit 1ccb405
committed
feat: Demonstrate String methods
🧪 Functionality:
1. Check if the string ends with `"Khan"` using `endsWith()`.
2. Fetch character at index `4` using `charAt(4)` — expected output: `'S'`.
3. Check if the substring starting from index 4 starts with `"Shah"` using `startsWith("Shah", 4)`.
4. Print each character of the string using a `for` loop with `charAt(i)`.
🧰 Methods Used:
- `String.endsWith(String suffix)` — checks if the string ends with the specified suffix.
- `String.charAt(int index)` — returns the character at the given index.
- `String.startsWith(String prefix, int offset)` — checks if the string starts with the specified prefix beginning at the given index.
- `String.length()` — gets the total number of characters in the string.
✅ Purpose:
To demonstrate character-wise access and common string checks (start, end, and offset-based prefix) in Java.
Signed-off-by: Somesh diwan <[email protected]>endsWith, charAt, startsWith with offset, and character iteration1 parent aebd2d4 commit 1ccb405
1 file changed
+2
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | | - | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | 14 | | |
17 | 15 | | |
0 commit comments