java中charat
A. java中關於charAT()的用法問題
publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubStringstr="student";for(inti=0;i<str.length();i++){System.out.println("=="+str.charAt(i));}
}
上例輸出:
==s==t==u==d==e==n==t
所以,charAt用法就是取出字元串第i個位置上的字元,返回char類型!!!!
B. charAt() Java中什麼作用 ~
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()方法.
packagecom.yii;
importjava.lang.*;
publicclassStringDemo{
publicstaticvoidmain(String[]args){
Stringstr="Thisisyii";
//printscharacterat1stlocation
System.out.println(str.charAt(0));
//printscharacterat5thlocationi.ewhite-spacecharacter
System.out.println(str.charAt(4));
//printscharacterat18thlocation
System.out.println(str.charAt(17));
}
}
編譯和運行上面的程序,這將產生以下結果。它也會列印空白字元。
T
p
C. java裡面charat什麼意思
charAt(int
index)方法是一個能夠用來檢索特定索引下的字元的String實例的方法.
charAt()方法返回指定索引位置的char值。索引范圍為0~length()-1.
如:
str.charAt(0)檢索str中的第一個字元,str.charAt(str.length()-1)檢索最後一個字元.
D. java中charat是什麼意思
是java中String的一個方法,如"dsagfjsadgf".chatAt(5); 代表的意思是從第0個開始取第5個,既j
不過使用的時候要注意長度,不要越界,否則會報java.lang.異常的
E. java charAt的用法
charat_網路charat(int
index)方法是一個能夠用來檢索特定索引下的字元的string實例的方法。
charat()方法返回一個位於提供給它的參數索引處的字元。
s.chatat(i)的意義就是,i為條件,就是第幾個字元,i的取值范圍為小於s的長度
F. java中charAt是什麼意思
charAt
public char charAt(int index)返回指定索引處的 char 值。索引范圍為從 0 到 length() - 1。序列的第一個 char 值位於索引 0 處,第二個位於索引 1 處,依此類推,這類似於數組索引。
如果索引指定的 char 值是代理項,則返回代理項值。
指定者:
介面 CharSequence 中的 charAt
參數:
index - char 值的索引。
返回:
此字元串指定索引處的 char 值。第一個 char 值位於索引 0 處。
拋出:
IndexOutOfBoundsException - 如果 index 參數為負或小於此字元串的長度。
G. Java里charAt具體用法
1.描述
java.lang.String.charAt() 方法返回指定索引處的char值。索引范圍是從0到length() - 1。對於數組索引,序列的第一個char值是在索引為0,索引1,依此類推,
2.聲明
以下是聲明java.lang.String.charAt()方法
public char charAt(int index)
參數
index -- 這是該指數的char值.
返回值
此方法返回這個字元串的指定索引處的char值。第一個char值的索引為0.
異常
IndexOutOfBoundsException -- 如果index參數為負或不小於該字元串的長度.
實例
3.下面的示例演示使用的java.lang.String.charAt()方法.
package com.yii;
import java.lang.*;
public class StringDemo {
public static void main(String[] args) {
String str = "This is yii";
// prints character at 1st location
System.out.println(str.charAt(0));
// prints character at 5th location i.e white-space character
System.out.println(str.charAt(4));
// prints character at 18th location
System.out.println(str.charAt(17));
}
}
編譯和運行上面的程序,這將產生以下結果。它也會列印空白字元。
T
p
H. Java中charAt超出范圍異常類型問題
1:第一次test("")返回的是2,第二次test("55")返回的是5,2+5=7,所以結果是7.
2:s.charAt(indexi)返回字元串s的角標為i的字元,因為第一次調用test(""),是空字元串,
所以s.chart(0)會產生角標溢出異常,而不是空指針異常,所以返回2。test("55"),s.chart(0)返回
'5','5'-'0'=5.
3:空指針異常是指變數為null,沒有進行初始化或者賦值,但是卻用這個變數了。就會產生空指針異常
I. java 方法CharAT()用來幹嘛
Java程序中strObj.charAt(index)方法,返回指定索引位置處的字元。CharAt()方法返回一個字元值,該字元位於指定索引位置。字元串中的第一個字元的索引為 0,第二個的索引為 1,等等。超出有效范圍的索引值返回空字元串。
//下面的示例說明了charAt()方法的用法
functioncharAtTest(n){
varstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ";//初始化變數。
vars;//聲名變數。
s=str.charAt(n-1);//從索引為n–1的位置處
return(s);//返回字元。
}
J. java方法charAt中,At代表什麼意思
JavaString類 charAt() 方法:
charAt() 方法用於返回指定索引處的字元。索引范圍為從 0 到 length() - 1。
語法:public char charAt(int index)
參數:index-- 字元的索引。
返回值:返回指定索引處的字元。
實例:
publicclassTest{
publicstaticvoidmain(Stringargs[]){
Strings="www.runoob.com";
charresult=s.charAt(4);
System.out.println(result);
}
}
運行結果:
r
s.charAt(4);可以理解成:s這個字元串在(At)索引為4的位置所對應的char值,At我的理解是「在什麼位置」的意思。
不知道這樣說樓主能明白么?樓主若覺得回答有所幫助,望採納,謝謝!