• Post Reply Bookmark Topic Watch Topic
  • New Topic

String a Wrapper Class  RSS feed

 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

It may seem a bit awkward but just wanted to know whether String Class is a wrapper class as it also wraps the characters which are primitive type. Okay can somebody tell me what exactly are wrapper classes ?

Thanks,
Rahul Juneja
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wrapper classes wrap primitives. For e.g. Integer wraps int,
Character wraps char. String is a sequnce of characters and does not wrap primitives.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java wrappers are classes that wrap up primitive values in classes that offer utility methods to manipulate the values. If for example you want to store a set of int values in the elements of a Vector, the values in a Vector must be objects and not primitives. When you want to retrieve the values wrapped up in the Integers that are in the Vector elements you will need to cast the elements back to Integers and then call the toxxValue in order to get back the original number. The following code demonstrates this technique.


The wrapper classes also offer utility methods for converting to and from the int values they represent. Thus if you have a string that could also represent a number, you can use a wrapper class to perform that calculation.
The methods of the wrapper classes are all static so you can use them without creating an instance of the matching wrapper
 
Vicky Jain
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pradeep,

Thats tha same i was trying to say him yday. Wrapper classer just wrap primitive data types.

Thanks
 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everybody. I understood ur poimnt guys. Can the Bartender or sheriff Please close this Topic.

Thanks,
Rahul Juneja
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!