Commit 9a3d2c4
committed
feat: Modify a string by converting to char array and replacing a character
🔍 What this code does:
- Converts the string `"abc"` to a character array using `toCharArray()`.
- Replaces the character at index 2 (`'c'`) with `'d'`.
- Converts the modified character array back to a string.
- Prints the new string, which becomes `"abd"`.
✅ Why:
Strings in Java are immutable. To change individual characters, convert to a char array, modify, then reconstruct the string.
Signed-off-by: Somesh diwan <[email protected]>1 parent f6c0260 commit 9a3d2c4
1 file changed
+8
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
13 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | | - | |
25 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | | - | |
| 35 | + | |
0 commit comments