Skip to content

Commit 857698e

Browse files
committed
feat: Convert string to char array and modify first character
🔍 What this code does: - Takes the string `"hello"` and converts it to a character array using `toCharArray()`. - Modifies the first character (`'h'`) to `'j'`. - Reconstructs a new string from the modified array. - Prints the result: `"jello"`. ✅ Why: This approach demonstrates how to modify specific characters in a string since strings in Java are immutable. Signed-off-by: Somesh diwan <[email protected]>
1 parent 9a3d2c4 commit 857698e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
class StringCC
2-
{
3-
public static void main(String[] args)
4-
{
1+
class StringCC {
2+
public static void main(String[] args) {
53
String x = "hello";
64
char[] xArray = x.toCharArray();
5+
76
xArray[0] = 'j';
87
x = new String(xArray);
98
System.out.println(x);
109
}
11-
}
10+
}

0 commit comments

Comments
 (0)