Click here to get the original English document Link
Today, when I looked at generics, I learned about the new features of JDK, including automatic packing and unboxing. below is my understanding of the original English document.
Any JavaProgramMembers know that you cannot put an int type (or other basic types) into a collection, and only object references can be loaded in the collection, so we need to wrap the basic type int (the int packaging class is integer ). When you extract an integer object from a set, you must call the intvalue () method to unpackage the integer object. Frequent unpacking and unpacking make it very painful.CodeIt looks messy. The automatic packing and unpacking process is automated, minimizing the above troubles.
Import Java. util. *; // prints a frequency table of the words on the command linepublic class frequency {public static void main (string [] ARGs) {Map <string, integer> M = new treemap <string, integer> (); For (string word: ARGs) {INTEGER freq = m. get (Word); M. put (word, (freq = NULL? 1: freq + 1);} system. Out. println (m );}}
the explanation of this Code is written according to your own understanding. There is no translation. In treemap, the object type is stored, now, the int type is automatically converted into an integer and saved to the map. when the data is accumulated, the integer type is converted into an int type for unboxing. Without this step, we need to tedious write as integer
I = new INTEGER (freq) for Integer Conversion and remove freq when adding. intvalue.