Skip to content

Commit aebd2d4

Browse files
committed
feat: Demonstrate use of replace and substring with trim on a String
🧪 Functionality: 1. Replace all occurrences of the character `'u'` with `'M'` in the original string. ➤ Input: "Abdul Bari Don" ➤ Output: "AbdMl Bari Don" 2. Extract a substring from index 3 (inclusive) to 5 (exclusive), and trim any whitespace. ➤ Substring: "ul" → After `trim()`: "ul" 🧰 Methods Used: - `String.replace(char oldChar, char newChar)` — Replaces each occurrence of the specified character. - `String.substring(int beginIndex, int endIndex)` — Extracts part of the string. - `String.trim()` — Removes leading and trailing whitespace. ✅ Purpose: Simple demonstration of basic `String` operations: replacement and substring extraction with trimming. Signed-off-by: Somesh diwan <[email protected]>
1 parent a637f88 commit aebd2d4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Section6StringClassPrinting/src/StringAB2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ public static void main(String[] args) {
88
String str2 = str.substring(3,5).trim();
99
System.out.println(str2);
1010
}
11-
}
11+
}

0 commit comments

Comments
 (0)