程式與日常
Java從字串取得指定索引位置的字元的方式如下。
使用String.charAt(int index),參數為索引。
String.charAt(int index)
例如下面取得字串hello的索引1的字元為e。
hello
e
package com.abc.demo; public class Main { public static void main(String[] arges) { System.out.println("hello".charAt(1)); // e } }
張貼留言
沒有留言:
張貼留言