English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

(a) What is a wrapper class?
(b) Autoboxing is the automatic conversion between a primitive value and a
corresponding wrapper object. Write two examples to explain the concepts
of autoboxing and unboxing between int and Integr.

2006-06-22 15:00:13 · 1 個解答 · 發問者 明煒 1 in 電腦與網際網路 程式設計

1 個解答

(a) What is a wrapper class?  Wrapper class is wrapper around a primitive data type. An instance of a wrapper class contains, or wraps, a primitive value of the corresponding type.  Following table lists the primitive types and the corresponding wrapper classes:PrimitiveWrapperbooleanjava.lang.Booleanbytejava.lang.Bytecharjava.lang.Characterdoublejava.lang.Doublefloatjava.lang.Floatintjava.lang.Integerlongjava.lang.Longshortjava.lang.Shortvoidjava.lang.Void(b) Autoboxing is the automatic conversion between a primitive value and acorresponding wrapper object. Write two examples to explain the conceptsof autoboxing and unboxing between int and Integr.1. A snippet from J2SE 5.0 in a Nutshell.  ArrayList list = new ArrayList();    list.add(0, 42);    int total = list.get(0);2. An example from Java Programming Languageimport java.util.*;// Prints a frequency table of the words on the command linepublic class Frequency {   public static void main(String[] args) {      Map m = new TreeMap();      for (String word : args) {          Integer freq = m.get(word);          m.put(word, (freq == null ? 1 : freq + 1));      }      System.out.println(m);   }To execute this class, please use the following command:java Frequency if it is to be it is up to me to do the watusiThe output should be just like this:{be=1, do=1, if=1, is=2, it=2, me=1, the=1, to=3, up=1, watusi=1}

2006-06-22 22:12:51 · answer #1 · answered by ? 7 · 0 0

fedest.com, questions and answers