Java chuyển đổi kiểu Short thành short primitive? (Java how to convert Short to short primitive?)


Bài viết này tôi sẽ hướng dẫn cách để chuyển đổi kiểu dữ liệu Short thành kiểu dữ liệu short primitive trong ngôn ngữ lập trình Java.





Mã nguồn - Source Code

/**
 * @(#)ConvertShortToShortPrimitive.java
 *
 * ConvertShortToShortPrimitive application
 *
 * @author Bui Ngoc Son
 * @web vnlives.net
 * @version 1.00 2014/6/12
 */

public class ConvertShortToShortPrimitive {
   
    public static void main(String[] args) {
       
        //Declare new Short object.
        Short sObj = new Short("666");
       
        //To convert Short to short use shortValue method of Short class.
        //Để chuyển đổi Short thành short sử dụng phương shortValue của lớp Short.
        short s = sObj.shortValue();
       
        System.out.println("Short converted to short: " + s);
       
    }
}




Kết quả - Result








No comments:

Post a Comment