Skip to content

Commit e186f41

Browse files
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

1 file changed

+1
-1
lines changed

Section6StringClassPrinting/Engineering Digest ED/src/TestString.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ public static void main(String[] args) {
2626
System.out.println('r'+0);
2727
System.out.println('c'+0); //114-99=15
2828
}
29-
}
29+
}

0 commit comments

Comments
 (0)