tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Commons Bean Utils > Primitive to Wrapper

Primitive to Wrapper 

Apache Commons BeanUtils is a java library useful for accessing bean properties and methods. It provides introspection capabilities to view and manipulate the properties and operations provided by the given class. This requires the libraries commons-beanutils-1.8.3.jar, commons-beanutils-bean-collections-1.8.3.jar, commons-beanutils-core-1.8.3.jar, commons-collections-3.2.1.jar, commons-logging.jar to be in classpath. The following example shows using MethodUtils.getPrimitiveWrapper() API. It returns the wrapper object class for the given primitive type.

File Name  :  
com/bethecoder/tutorials/commons_beanutils/Primitive2WrapperTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.commons_beanutils;

import org.apache.commons.beanutils.MethodUtils;

public class Primitive2WrapperTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    
    Class<?> primitiveType = MethodUtils.getPrimitiveWrapper(int.class);
    System.out.println(primitiveType);
    
    primitiveType = MethodUtils.getPrimitiveWrapper(char.class);
    System.out.println(primitiveType);
    
    primitiveType = MethodUtils.getPrimitiveWrapper(short.class);
    System.out.println(primitiveType);
    
    primitiveType = MethodUtils.getPrimitiveWrapper(double.class);
    System.out.println(primitiveType);
  }

}
   

It gives the following output,
class java.lang.Integer
class java.lang.Character
class java.lang.Short
class java.lang.Double



 
  


  
bl  br