Get char in a string by index in Java
Description
The following code shows how to get char in a string by index.
Example
//w ww .ja v a 2 s . c o m
public class Main {
public static void main(String[] av) {
String a = "java2s.com";
for (int i=0; i < a.length(); i++)
System.out.println("Char " + i + " is " + a.charAt(i));
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »