Java Short valueOf()方法

java.lang.Short.valueOf(String s) 方法返回保持由指定的字符串中给定值的Short对象。

1 语法

public static Short valueOf(String s) throws NumberFormatException

2 参数

s :这是要被解析的字符串。

3 返回值

此方法返回保持由字符串参数表示的值的Short对象。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * Java Short valueOf()方法
 */
import java.lang.*;

public class ShortDemo {

   public static void main(String[] args) {

     short shortNum = 100;
     String str = "600";
    
     // returns Short object representing given short value
     Short ShortValue = Short.valueOf(shortNum);
     // displays the short object value
     System.out.println("Short object representing the specified short value =
     " + ShortValue);
     
     // returns a Short object holding the value given by the specified String
     ShortValue = Short.valueOf(str); 
     // displays the short object value
     System.out.println("Short object holding the value given by the specified
     String = " + ShortValue);
  }
}

输出结果为:

Short object representing the specified short value = 100
Short object holding the value given by the specified String = 600

 

热门文章

优秀文章