Java charAt() 方法
charAt() 方法用於返回指定索引處的字符。索引範圍爲從 0 到 length() - 1。
語法
public char charAt(int index)
參數
-
index -- 字符的索引
返回值
返回指定索引處的字符
字符串長度爲str.length();
字符串數組長度爲persons.length;
package com.alibaba.searchRecall.utils;
public class searchQuery {
public static void main(String[] args) {
String str = "林正英,趙露思,黃景瑜,迪麗熱巴,xx";
String[] persons = str.split(",");
for (int i = 0; i < persons.length; i++) {
String everyOne = persons[i];
System.out.println("第" + (i + 1) + "個人物爲==" + everyOne);
}
System.out.println("--------------------------------------------------");
String strChar = "林正英,趙露思";
for (int i = 0; i < strChar.length(); i++) {
char c = strChar.charAt(i);
System.out.println("第" + (i + 1) + "個位置,單個字符爲==" + c);
}
}
}