Commit e186f41
committed
feat: Add TestString class to demonstrate Java String operations
- Introduced `TestString` class to illustrate common String methods and comparisons.
- Used `length()` to get the number of characters in a String.
- Demonstrated `charAt(index)` to access specific characters:
- Extracted a character from a hardcoded index (`6`) in "Virat Kohli"
- Used `length - 1` to get the last character of "Ram"
- Compared two strings (`name` and `name1`) using:
- `equals()` — case-sensitive comparison
- `equalsIgnoreCase()` — case-insensitive comparison
- Compared `str1 = "remote"` and `str2 = "car"` using `compareTo()` to demonstrate lexicographical comparison based on ASCII values.
- Printed ASCII values of characters 'r' and 'c' using `'char' + 0` trick.
This commit provides a basic reference for String manipulation, comparison, and character operations in Java.
Signed-off-by: Somesh diwan <[email protected]>1 parent 28db03f commit e186f41
File tree
1 file changed
+1
-1
lines changed- Section6StringClassPrinting/Engineering Digest ED/src
1 file changed
+1
-1
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
0 commit comments