Wrapper Classes in JAVA

Wrapper Classes in JAVA

Wrapper classes is a way to use java primitive types as objects. It can be used in generics when we want to use primitive types. Each primitive type has its own wrapper class

  • boolean: Boolean
  • byte: Byte
  • char: Character
  • float: Float
  • int: Integer
  • long: Long
  • short: Short
  • double: Double
import java.util.List;
import java.util.ArrayList;

public class WrapperClasses {

    public static void main(String args[]) {
        // This is not working
        List list = new ArrayList<>();

        // Use this instead
        List list = new ArrayList<>();

        int i = 2;
        list.add(i);
    }

}