JDK 1.5 Characteristics Example 3 - AutoBoxing

xiaoxiao2021-03-06  78

Package maoxiang.examples.jdk15;

Import java.util.abstractList;

Import java.util.list;

Import java.util.map;

Import java.util.treemap;

/ **

* @Author Mao Xiang

*

* Box converts the Primitive type into a compound object, such as converting Int into Integer

* Unbox converts a compound object to Primitive Integer.intValue ()

* /

Public class autoBoxing {

Public static void main (String [] args) {

Autoboxing test = new autoboxing ();

Test.test1 ();

}

Public void test1 () {

String [] args = new string [] {"1", "2", "3", "4", "5", "6", "7", "8"};

Map m = new trememap ();

For (String Word: args) {

Integer freq = m.get (Word);

M.PUT (Word, (freq == NULL? 1: FREQ 1);

}

System.out.println (M);

}

// list adapter for primitive int arch

Public Static List Aslist (Final Int [] a) {

Return New AbstractList () {

Public Integer Get (INT I) {

Return a [i];

}

// throws nullpointersRexception if Val == NULL

Public Integer Set (INT I, Integer Val) {

Integer OldVal = a [i];

a [i] = val;

Return OldVal;

}

Public int size () {

Return A.Length;

}

}

}

}

转载请注明原文地址:https://www.9cbs.com/read-108570.html

New Post(0)