zoukankan      html  css  js  c++  java
  • Java引进和应用的包装类

    Java介绍包装类:

    于Java它设计主张的想法,也就是说,一切都是对象.但是,我们知道,,Java数据类型分为基本数据类型和引用数据类型,但基本的数据怎么能成对象?为了解决这个问题,对需要8一个类的形式,这就是包装类的作用.


    装箱与拆箱:

    public class WrapperDemo01{
    	public static void main(String args[]){
    		int x = 30 ;		// 基本数据类型
    		Integer i = new Integer(x) ;	// 装箱:将基本数据类型变为包装类
    		int temp = i.intValue()	;// 拆箱:将一个包装类变为基本数据类型
    	}
    };

    包装类的应用:

    包装类在实际中用得最多的还是字符串变为基本数据类型的操作

    public class WrapperDemo02{
    	public static void main(String args[]){
    		String str1 = "30" ;	// 由数字组成的字符串
    		String str2 = "30.3" ;	// 由数字组成的字符串
    		int x = Integer.parseInt(str1) ;	// 将字符串变为int型
    		float f = Float.parseFloat(str2) ;	// 将字符串变为int型
    		System.out.println("整数乘方:" + x + " * " + x + " = " + (x * x)) ;
    		System.out.println("小数乘方:" + f + " * " + f + " = " + (f * f)) ;
    	}
    };


    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    查看SQL Server版本号(2005 & 2008)
    Installing an App for Testing
    Viewstate 的用法
    How to Open the Pdf file?
    工具类:Log
    SPSiteDataQuery and SPQuery
    SPSite, SPWeb Dispose and Class Design Partter
    Add Properties or Delete List Folder Content Type
    SharePoint UserControl
    Click Once 布署
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/4910486.html
Copyright © 2011-2022 走看看