該方法用於獲取某個字符串的原始數據類型。 parseXxx() 是一種靜態方法,可以有一個或兩個參數。
用法
static int parseInt(String s) static int parseInt(String s, int radix)
參數
s- 這是十進製的字符串表示。
radix- 這將用於將 String s 轉換為整數。
返回值
parseInt(String s)- 這將返回一個整數(僅限十進製)。
parseInt(int i)- 這將返回一個整數,給定十進製、二進製、八進製或十六進製(基數分別等於 10、2、8 或 16)數字的字符串表示作為輸入。
示例
以下是使用此方法的示例 -
class Example {
static void main(String[] args) {
int x = Integer.parseInt("9");
double y = Double.parseDouble("5");
int z = Integer.parseInt("444",16);
System.out.println(x);
System.out.println(y);
System.out.println(z);
}
}
當我們運行上述程序時,我們將得到以下結果 -
9 5.0 1092
相關用法
- Groovy padRight()用法及代碼示例
- Groovy padLeft()用法及代碼示例
- Groovy pow()用法及代碼示例
- Groovy put()用法及代碼示例
- Groovy matches()用法及代碼示例
- Groovy after()用法及代碼示例
- Groovy contains()用法及代碼示例
- Groovy exp()用法及代碼示例
- Groovy equals()用法及代碼示例
- Groovy before()用法及代碼示例
- Groovy sin()用法及代碼示例
- Groovy concat()用法及代碼示例
- Groovy random()用法及代碼示例
注:本文由純淨天空篩選整理自 Groovy - parseInt()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。