方法 | 描述 |
---|---|
static Integer decode(String s) | 將字串解碼為數字 |
舉例如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | class DecodeDemo { public static void main(String[] args) { String s = "22" ; Integer i = Integer.decode(s); System.out.println(i); } } /* 《程式語言教學誌》的範例程式 檔名:DecodeDemo.java 功能:示範物件導向的基本觀念 作者:張凱慶 時間:西元 2010 年 10 月 */ |
編譯後執行,結果如下

其中,第 4 行,其為呼叫 decode() 方法的地方
4 | Integer i = Integer.decode(s); |
這樣變數 i 便會儲存 s 中所具有的整數數值。
中英文術語對照 | |
---|---|
字串 | string |
物件 | object |
沒有留言:
張貼留言