Username: Save?
Password:
Home Forum Links Search Login Register*
    News: Keep The TechnoWorldInc.com Community Clean: Read Guidelines Here.
Recent Updates
[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[February 14, 2024, 02:00:39 PM]
Subscriptions
Get Latest Tech Updates For Free!
Resources
   Travelikers
   Funistan
   PrettyGalz
   Techlap
   FreeThemes
   Videsta
   Glamistan
   BachatMela
   GlamGalz
   Techzug
   Vidsage
   Funzug
   WorldHostInc
   Funfani
   FilmyMama
   Uploaded.Tech
   MegaPixelShop
   Netens
   Funotic
   FreeJobsInc
   FilesPark
Participate in the fastest growing Technical Encyclopedia! This website is 100% Free. Please register or login using the login box above if you have already registered. You will need to be logged in to reply, make new topics and to access all the areas. Registration is free! Click Here To Register.
+ Techno World Inc - The Best Technical Encyclopedia Online! » Forum » THE TECHNO CLUB [ TECHNOWORLDINC.COM ] » Programming Zone » JAVA
 Java: Wrapper Classes
Pages: [1]   Go Down
  Print  
Author Topic: Java: Wrapper Classes  (Read 2978 times)
Admin
Administrator
Adv. Member
*****



Karma: 208
Offline Offline

Posts: 496

TWI Admin

159511729 vatsal2002 superwebchampz
View Profile WWW
Java: Wrapper Classes
« Posted: January 01, 2007, 02:17:29 AM »


Decription on going to and from the java Object wrapper classes.

Wrapper classes to exactly what they say, they wrap primitive types (eg: int, double, etc) in Objects which can be placed into Vectors, and many, many other uses.

*Notice that an Object starts with a capital letter, while the primitives all start with a lowercase. Also notice that Strings are Ojects.

These Wrapper classes can be created in many ways, so i will start slow, simply returning objects with a String.

Integer from String:
Integer i = Integer.valueOf("125");

Double from String:
Double d = Double.valueOf("5.829754097");

Float from String:
Float f = Float.valueOf("8.43543");

Boolean from String:
Boolen b = Boolean.valueOf("true");
//This will represent true

Character from String:
Character c = Character.valueOf("G");


The more common use is given the primitive in a variable. This next section shows how to convert a variable to these wrapper classes and back to a primitive.

Integer:
int i = 5;
Integer I = Integer.valueOf(i); //Wrapper
int i2 = I.intValue(); //back to primitive

Float:
float f = 5.5f;
Float F = Float.valueOf(f); //Wrapper
float f2 = F.floatValue(); //back to primitive

Double:
double d = 5.55555;
Double D = Double.valueOf(d); //Wrapper
double d2 = D.doubleValue(); //back to primitive

Boolean:
boolean b = true;
Boolean B = Boolean.valueOf(b); //Wrapper
boolean b2 = B.booleanValue(); //back to primitive


*When dealing with strings you may also wish to use the following to get primitives from the Object String:

Integer:
int i = Integer.parseInt("234");

Double
double d = Double.parseDouble("234.6576533254");

Float:
float f = Float.parseFloat("234.78");

Long:
long l = Long.parseLong("23454654");

*Note you may wish to add the ().trim feature to these last ones, in the case of extra white space around your String, which may cause exceptions.
Example of trim:
String s = " William "; // displays as ' William '
String s2 = (s).trim(); //displays 'William'

Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Copyright © 2006-2023 TechnoWorldInc.com. All Rights Reserved. Privacy Policy | Disclaimer
Page created in 0.078 seconds with 24 queries.