用于獲取有關(guān)對象的信息的方法稱為訪問器方法。
String類的一個訪問器方法是length()方法,它返回字符串對象包含的字符數(shù)。
下面的代碼執(zhí)行后,len變量等于17:
public class StringDemo { public static void main(String args[]) { String palindrome = "Dot saw I was Tod"; int len = palindrome.length(); System.out.println( "String Length is : " + len ); } }
以上實例編譯運行結(jié)果如下:
String Length is : 17
![]() | ![]() .. 定價:¥45 優(yōu)惠價:¥42 更多書籍 |
![]() | ![]() .. 定價:¥225 優(yōu)惠價:¥213 更多書籍 |