Mega Code Archive

 
Categories / Java / Collections Data Structure
 

Storing Primitive Types in a Collection

import java.util.HashMap; import java.util.Map; public class Main {   public static void main(String[] argv) throws Exception {     Map map = new HashMap();     // Create int wrapper object     Integer refInt = new Integer(123);     // Store int in map     map.put("key", refInt);     // Get int value from map     refInt = (Integer) map.get("key");     // Get the integer value from wrapper object     int i = refInt.intValue();   } }