字符 字符串數組 字符串取值

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);
        }

    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章