为什么我们需要包装类?如果是这样,那个包装类意味着什么? [英] why we need wrapper class?If so what is that wrapper class meant?

查看:121
本文介绍了为什么我们需要包装类?如果是这样,那个包装类意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们需要包装类?

我们实现了什么包装类?

如何创建Wrapper类?并举一些这样的例子?

Wrapper类的属性?

Why we need wrapper class?
What we are achieving wrapper class?
How to create Wrapper class?and Give some example of this?
Properties of Wrapper class?

推荐答案

Wrapper类只包含原始数据类型的对象,即int,double,float等。

但是,在开发过程中,我们遇到了需要使用对象而不是原始数据类型的情况。为了实现这个目的,Java为每个原始数据类型提供了包装类。 ie Socket 远程编程



参考:

http://way2java.com/java-lang/wrapper-classes/ [ ^ ]

http://stackoverflow.com/questions/3579035/why-are-there- wrapper-classes-in-java [ ^ ]

http://www.tutorialspoint.com /java/java_numbers.htm [ ^ ]



-KR
Wrapper class in nothing but the object of your primitive data types i.e int, double, float etc.
However, in development, we come across situations where we need to use objects instead of primitive data types. In-order to achieve this Java provides wrapper classes for each primitive data type. i.e Socket or Remote Programming

Refer this:
http://way2java.com/java-lang/wrapper-classes/[^]
http://stackoverflow.com/questions/3579035/why-are-there-wrapper-classes-in-java[^]
http://www.tutorialspoint.com/java/java_numbers.htm[^]

-KR


包装类允许将原始数据类型作为对象进行访问。它们是每个基本类型一个:布尔值,字节,字符,双精度,浮点数,整数,长和短。包装类使原始类型数据充当对象。



为什么我们可以使用?

处理原语作为对象有时更容易。大多数对象集合存储对象而不是基本类型。包装类提供了许多实用方法。为了获得这些优势,我们需要使用包装类。因为它们是对象,所以它们可以存储在任何集合中,并将此集合作为参数传递给方法。

Java包装器类的功能。



-Wrapper类将数字字符串转换为数值。

-在对象中存储原始数据的方法。

- valueOf()方法可用在除Character之外的所有包装类中

- 所有包装类都有typeValue()方法。此方法返回对象的值作为其基本类型。
Wrapper classes allow primitive data types to be accessed as objects. They are one per primitive type: Boolean, Byte, Character, Double, Float, Integer, Long and Short. Wrapper classes make the primitive type data to act as objects.

why we can use?
Dealing with primitives as objects is easier at times. Most of the objects collection store objects and not primitive types. Many utility methods are provided by wrapper classes. To get these advantages we need to use wrapper classes. As they are objects, they can be stored in any of the collection and pass this collection as parameters to the methods.
Features of the Java wrapper Classes.

-Wrapper classes convert numeric strings into numeric values.
-The way to store primitive data in an object.
-The valueOf() method is available in all wrapper classes except Character
-All wrapper classes have typeValue() method. This method returns the value of the object as its primitive type.


这篇关于为什么我们需要包装类?如果是这样,那个包装类意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆