| Author |
Why Does Java Support both Wrapper Classes & Primitive types?
|
Waez Ali
Greenhorn
Joined: Jan 10, 2005
Posts: 22
|
|
Hi, I just want to know, 1) Why does Java support both int & Integer, char & Charecter, and so on........? 2) When should we use these classes? Please let me know this concept. Thank You
|
 |
Lionel Badiou
Ranch Hand
Joined: Jan 06, 2005
Posts: 140
|
|
Hi Ali, 'int' and 'char' are basic types whereas 'Integer' and 'Character' are classes. You may find a detailed explanation here Best regards,
|
Lionel Badiou
CodeFutures Software
|
 |
Lionel Badiou
Ranch Hand
Joined: Jan 06, 2005
Posts: 140
|
|
oops ;-) It seems that the link I have just provided forget to mention a noticeable point : basic types can't be used in association with Java Collections (ArrayList, Vector ...) whereas wrapper classes can. For example, you may declare a HashMap of 'Integer' but not a HashMmap of 'int' (as the Java collections work only on objects) Best regards,
|
 |
Waez Ali
Greenhorn
Joined: Jan 10, 2005
Posts: 22
|
|
Hello Peter, I was so confused but I got it now You are just great. Thank you Waez Ali.
|
 |
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
|
|
Primitive values should typically be preferred when doing extensive calculations. As mentioned, wrapper classes are helpful when you need to store primitives in a Collection. Since you cannot do this directly, the wrapper classes are necessary. Layne
|
Java API Documentation
The Java Tutorial
|
 |
Preetham Chandrasekhar
Ranch Hand
Joined: Nov 05, 2003
Posts: 98
|
|
|
cant use primitive types in Collections which form a major part of the Java programming language for managing the data structures.
|
"In theory, there is no difference between theory and practice. But, in practice, there is."<br /> - Jan L.A. van de Snepscheut
|
 |
Preetham Chandrasekhar
Ranch Hand
Joined: Nov 05, 2003
Posts: 98
|
|
|
cant use primitive types in Collections which form a major part of the Java programming language for managing the data structures.
|
 |
 |
|
|
subject: Why Does Java Support both Wrapper Classes & Primitive types?
|
|
|