- Groovy 教程
- Groovy - 首頁
- Groovy - 概述
- Groovy - 環境搭建
- Groovy - 基本語法
- Groovy - 資料型別
- Groovy - 變數
- Groovy - 運算子
- Groovy - 迴圈
- Groovy - 條件判斷
- Groovy - 方法
- Groovy - 檔案 I/O
- Groovy - 可選值
- Groovy - 數字
- Groovy - 字串
- Groovy - 範圍
- Groovy - 列表
- Groovy - 對映
- Groovy - 日期和時間
- Groovy - 正則表示式
- Groovy - 異常處理
- Groovy - 面向物件程式設計
- Groovy - 泛型
- Groovy - 特性 (Traits)
- Groovy - 閉包
- Groovy - 註解
- Groovy - XML 處理
- Groovy - JMX
- Groovy - JSON 處理
- Groovy - DSLs
- Groovy - 資料庫操作
- Groovy - 構建器
- Groovy - 命令列
- Groovy - 單元測試
- Groovy - 模板引擎
- Groovy - 元物件程式設計
- Groovy 資源推薦
- Groovy - 快速指南
- Groovy - 資源推薦
- Groovy - 討論
Groovy - valueOf() 方法
valueOf 方法返回包含傳入引數值的相應 Number 物件。引數可以是基本資料型別、字串等。
此方法是靜態方法。該方法可以接受兩個引數,其中一個是字串,另一個是基數。
語法
static Integer valueOf(int i) static Integer valueOf(String s) static Integer valueOf(String s, int radix)
引數
以下是引數的詳細說明:
i − 一個 int 值,將返回其 Integer 表示。
s − 一個 String 值,將返回其 Integer 表示。
radix − 基數,用於根據傳入的字串確定返回的 Integer 值。
返回值
valueOf(int i) − 返回一個包含指定基本數值的 Integer 物件。
valueOf(String s) − 返回一個包含指定字串表示值的 Integer 物件。
valueOf(String s, int radix) − 返回一個包含指定字串表示的整數數值的 Integer 物件,該數值根據基數進行解析。
示例
以下是此方法用法的示例:
class Example {
static void main(String[] args) {
int x = 5;
Double z = 15.56;
Integer xNew = Integer.valueOf(x);
println(xNew);
Double zNew = Double.valueOf(z);
println(zNew);
}
}
執行上述程式後,將得到以下結果:
5 15.56
groovy_numbers.htm
廣告