Java String charAt(): Extract Characters Guide

In Java, you can use the charAt() method to extract characters from a string. This method takes an integer parameter that represents the index position of the character to be extracted. The index position starts from 0, where 0 represents the first character of the string.

Here is an example code demonstrating how to extract characters from a string.

String str = "Hello World";
char ch = str.charAt(0);
System.out.println(ch); // 输出字符'H'

You can also use a loop structure to extract each character from the string one by one.

String str = "Hello World";
for(int i = 0; i < str.length(); i++) {
   char ch = str.charAt(i);
   System.out.println(ch); // 逐个输出字符串中的字符
}

This code will output each character in the string one by one.

bannerAds