Skip to content

Commit 068e82a

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 857698e commit 068e82a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Section6StringClassPrinting/src/StringCC.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ public static void main(String[] args) {
66
xArray[0] = 'j';
77
x = new String(xArray);
88
System.out.println(x);
9+
10+
for(int i = 0; i < xArray.length; i++) {
11+
System.out.println(xArray[i]);
12+
}
913
}
1014
}

0 commit comments

Comments
 (0)