String charAt() Method
Java String charAt() returns the character located at the specified index in String. The string indexes start from zero and ranges from 0 to length() - 1. 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()
Java String toUpperCase() converting the string to uppercase without needing to assign the result to a new variable. 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()
Java String toLowerCase() converting the string to lowercase without needing to assign the result to a new variable. Example
class TestClass {
public static void main (String[] args) {
String str = "JAVA STRING TUTORIAL";
System.out.println(str.toLowerCase() );
}
}
Related Topics
- How to Get the Length of a String
- String indexOf() method
- Java String replace()
- Java String contains()
- String Comparison in Java
- Java String substring()
- Java String concat() Method
- Java String split() method
- Convert String to int
- Java StringBuilder Class
- StringTokenizer in Java
- How to convert int to String in Java?