String charAt() Method

The Java String charAt() method retrieves and returns the character at the specified position within a String. In Java, strings are indexed starting from zero, and the valid index range spans from 0 to length() - 1, where length() represents the total number of characters in the string. By utilizing the charAt() method, developers can access and manipulate individual characters within a string by referencing their corresponding index positions.

Syntax:
public char charAt(int index)
Example
class TestClass { public static void main (String[] args) { String str = "Halo World!"; System.out.println(str.charAt(0)); System.out.println(str.charAt(3)); System.out.println(str.charAt(9)); } }
Output
H o d

It is important to note that, it will thrown an IndexOutOfBoundsException if the index is less than zero or greater than equal to the length of the string (index<0 index>=length()).

String Change to Uppercase

String toUpperCase()

The Java String toUpperCase() method allows for the conversion of a string to its uppercase form without the need to create a new variable to store the result. By invoking this method on a string object, the original string is transformed to uppercase characters, while the resulting uppercase string is returned. This provides a convenient and efficient way to modify the case of a string directly without the necessity of extra variable assignments.

Example
class TestClass { public static void main (String[] args) { String str = "java string tutorial"; System.out.println(str.toUpperCase() ); } }

String Change to Lowecase

String toLowerCase()

The Java String toLowerCase() method facilitates the conversion of a string to its lowercase form without requiring the creation of a new variable to hold the result. When invoked on a string object, this method modifies the original string by transforming its characters to lowercase, and subsequently returns the resulting lowercase string. This functionality allows for the direct modification of a string's case without the need for additional variable assignments, providing a convenient and efficient approach.

Example
class TestClass { public static void main (String[] args) { String str = "JAVA STRING TUTORIAL"; System.out.println(str.toLowerCase() ); } }

Conclusion

The charAt() method in Java is used to retrieve the character at a specific index within a string. It returns the character value at the given position, allowing easy access to individual characters in a string by their index.