Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Intermediate
Mar 2, 2004



Application Security Testing: An Integral Part of DevOps


The problem with the collection API is that you cannot put primitive data types into it. Instead, you must use their object counter parts. For instance, you have to use the Integer class and convert back and forth, like this:

int rate = 3;

Vector vec = new Vector();

vec.addElement(new Integer(rate));

//   do what ever 

int result = ((Integer)vec.lastElement()).intValue();
The following code uses the new features of JDK 1.5 for greater ease of development. In it, the compiler takes all the responsibility of converting back and forth. Moreover, this code is a lot more concise:

            int rate = 3;

                Vector vec = new Vector();

// don't need to do conversion

//  do your implementation 


                int result = vec.lastElement();   
// don't need to convert here as well
Autoboxing and unboxing allows you to focus on your task rather than the language itself.
M.Fahim Zahid
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date