android String.charAt的使用
生活随笔
收集整理的這篇文章主要介紹了
android String.charAt的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
今天,簡單講講String里的
charAt()的使用。
描述
java.lang.String.charAt()?方法返回指定索引處的char值。索引范圍是從0到length() - 1。對于數組索引,序列的第一個char值是在索引為0,索引1,依此類推,
聲明
以下是聲明java.lang.String.charAt()方法
public char charAt(int index)參數
-
index?-- 這是該指數的char值.
返回值
此方法返回這個字符串的指定索引處的char值。第一個char值的索引為0.
異常
-
IndexOutOfBoundsException?-- 如果index參數為負或不小于該字符串的長度.
實例
下面的示例演示使用的java.lang.String.charAt()方法.
package com.yiibai;import java.lang.*;public class StringDemo {public static void main(String[] args) {String str = "This is yiibai";// prints character at 1st locationSystem.out.println(str.charAt(0));// prints character at 5th location i.e white-space characterSystem.out.println(str.charAt(4));// prints character at 18th location System.out.println(str.charAt(17));} }
讓我們編譯和運行上面的程序,這將產生以下結果。它也會打印空白字符。
Tp
這個實在太簡單了,其實使用String.subString(i,i+1)也可以實現同樣的效果。
android String.charAt的使用就講完了。
就這么簡單。
總結
以上是生活随笔為你收集整理的android String.charAt的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android Android项目构建过
- 下一篇: android 获取apk里的xml文件