java中对字符串的常用取值方法
public class stringPro {
public static void main(String[] args) {
String strData = "a-bc";
// 返回指定字符在字符串中的索引位置
int strIndex = strData.indexOf("-");
System.out.println(strIndex);
System.out.println("------------------");
//通过索引位置 返回字符串指定索引位置上的字符
char dataByIndex = strData.charAt(2);
System.out.println(dataByIndex);
System.out.println("------------------");
// 返回一个新的字符串,它是此字符串的一个子字符串。
// 该子字符串始于指定索引处的字符,一直到此字符串索引末尾
String substring = strData.substring(1);
System.out.println(substring);
}
}
输出为:
1
------------------
b
------------------
-bc