JDK 1.5 特性使用实例3--AutoBoxing
来源:互联网 发布:软件用户手册使用步骤 编辑:程序博客网 时间:2024/05/17 18:47
package maoxiang.examples.jdk15;
import java.util.AbstractList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
/**
* @author 毛翔
*
* box 将primitive 类型转换成复合对象 ,如将int 转换成Integer
* unbox 将复合对象转换成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<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);
}
// List adapter for primitive int array
public static List<Integer> asList(final int[] a) {
return new AbstractList<Integer>() {
public Integer get(int i) {
return a[i];
}
// Throws NullPointerException 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;
}
};
}
}
- JDK 1.5 特性使用实例3--AutoBoxing
- JDK 1.5 特性使用实例1--Generics
- JDK 1.5 特性使用实例2--Varargs
- JDK 1.5 特性使用实例4--Enum
- JDK 1.5 特性使用实例5--metadata
- JDK 1.5 特性使用实例6--staticimport
- JDK 1.5 特性使用实例7--运行外部程序
- Quick reference of Autoboxing in JDK 1.5
- jdk 1.5 新特性 3
- autoboxing
- autoBoxing
- J2SE 5.0的新特性---Autoboxing
- JDK 1.5 特性
- JDK 1.5新特性
- JDK 1.5 新特性
- JDK 1.5新特性
- JDK 1.5 新特性
- JDK 1.5 新特性
- 通用的STOP故障处理方法和特殊的STOP故障排除
- Java游戏编程初步
- JDK 1.5 特性使用实例2--Varargs
- Java 多线程入门大全
- 利用 Ant 和 JUnit 进行开发
- JDK 1.5 特性使用实例3--AutoBoxing
- What is Favicon.ico? Personalise Your Site's Bookmark(zt)
- JDK 1.5 特性使用实例4--Enum
- javascript 怎样比较日期/时间的大小
- Log4J与JBuilder、Eclipse配合使用指南
- JDK 1.5 特性使用实例5--metadata
- 缩小SQL SERVER日志文件
- JDK 1.5 特性使用实例6--staticimport
- 免费申请优易普企业管理软件注册码!!!