Generics and Collection (1)
public static void main(String args[]) {
List ints = Arrays.asList(new Integer[]{new Integer(), new Integer()});
int s =;
for(Iterator it = ints.iterator(); it.hasNext();)
{
int n = ((Integer)it.next()).intValue();
s+=n;
}
System.out.println(s);
}
public static void main(String args[]) {
List<Integer> ints = Arrays.asList(,,);
int s = ;
for(int n: ints)
{
s+=n;
}
System.out.println(s);
}
public static void main(String args[]) {
List<String> words = new ArrayList<String>();
words.add("Hello");
words.add("world");
String s = words.get() +words.get();
System.out.println(s);
}
package cn.galc.test;
import java.util.*;
class Lists{
public static <T> List<T> toList(T[] arr)
{
List<T> list = new ArrayList<T>();
for (T t: arr)
{
list.add(t);
}
return list;
}
}
public class Test {
public static void main(String args[]) {
List<String> words = Lists.toList(new String[]{"sun","ming"});
for(String s:words)
System.out.println(s);
}
}
Generics and Collection (1)的更多相关文章
- Generics and Collection (2)
Integer is a subtype of NumberDouble is a subtype of NumberArrayList<E> is a subtype of List&l ...
- Java中Generics的使用
1.Java的Generics与C++的Template由于Java的Generics设计在C++的Template之后,因此Java的Generics设计吸取Template的很多经验和教训.首先, ...
- 最佳新秀Java(22)——再次了解泛型
仿制药Java SE 1.5新功能.通用自然是参数化类型.即操作数据类型被指定为一个参数.这样的参数类型可以在课堂上使用.创建的接口和方法,他们被称为通用类..泛型方法. Java语言引入泛型的优点是 ...
- Swift 学习笔记(四)
116.使用可选链式调用代替强制展开 通过在想调用的属性.方法.或下标的可选值(optional value)后面放一个问号(?),可以定义一个可选链.这一点很像在可选值后面放一个叹号(!)来强制展开 ...
- 菜鸟学Java(二十二)——重新认识泛型
泛型是Java SE 1.5的新特性,泛型的本质是参数化类型,也就是说所操作的数据类型被指定为一个参数.这种参数类型可以用在类.接口和方法的创建中,分别称为泛型类.泛型接口.泛型方法. Java语言引 ...
- 菜鸟学Java(二十二)——又一次认识泛型
泛型是Java SE 1.5的新特性,泛型的本质是參数化类型,也就是说所操作的数据类型被指定为一个參数.这样的參数类型能够用在类.接口和方法的创建中,分别称为泛型类.泛型接口.泛型方法. Java语言 ...
- 12.Generics
benifit: 1.make developers extremely productive is code reuse, which is the ability to derive a clas ...
- JDK1.5新特性(六)……Generics
概述 Generics - This long-awaited enhancement to the type system allows a type or method to operate on ...
- thinking in java Generics Latent typing
The beginning of this chapter introduced the idea of writing code that can be applied as generally a ...
随机推荐
- javascript中日期格式与时间戳之间的转化
日期格式与时间戳之间的转化 一:日期格式转化为时间戳 function timeTodate(date) { var new_str = date.replace(/:/g,'-'); new_str ...
- IE报错:模块"scrrun.dll"已加载,但对DllRegisterServer的调用失败,错误代码为0x80004005
在我的win10系统上打开某内部网页登录的时候弹出'模块"scrrun.dll"已加载,但对DllRegisterServer的调用失败,错误代码为0x80004005'报错信息, ...
- 利用Continuous Testing实现Eclipse环境自动单元测试
当你Eclipse环境中修改项目中的某个方法时,你可能由于各种原因没有运行单元测试,结果代码提交,悲剧就可能随之而来. 所幸infinitest(http://infinitest.github.io ...
- Map接口
Map实现的包括HashMap 和TreeMap .建议使用HashMap ,效率更高.并且允许使用null值,单是必须保证键的唯一性,TreeMap不允许有空.在添加删除和定位映射关系的时候不如Ha ...
- OpenStreetMap/Google/百度/Bing瓦片地图服务(TMS)
开源与成熟商业的瓦片地图服务(TMS 2 WMTS),都有如下共同的特性,基本成为了标准: (1) 坐标系:WGS84 (2) 投影:墨卡托投影(Marcator,正轴等角圆柱投影) ------ ...
- 将Web站点由IIS6迁移至IIS7
最近开始着手逐步将所有的Web站点由Win2003+IIS6迁移至64位Win2008+IIS7,基本还算顺利.这里就把相关内容整理总结一下.首先自然是要安装基本运行环境,包括iis,.net fra ...
- C++设计模式-Facade模式
Facade模式 作用:为子系统中的一组接口提供一个一致的界面,Facade模式定义了一个高层接口,这个接口使得这一子系统更加容易使用. 动机 将一个系统划分成为若干个子系统有利于降低系统的复杂性.一 ...
- AE IRasterCursor 改变栅格图层像素值
1 public void ChangePixelValue(double xMax, double xMin, double yMax, double yMin,double[,] PixelCha ...
- clientTop、offsetTop和scrollTop的区分
页可见区域宽: document.body.clientWidth; 网页可见区域高: document.body.clientHeight; 网页可见区域宽: document.body.offse ...
- leetcode-【中等题】Divide Two Integers
题目 Divide two integers without using multiplication, division and mod operator. If it is overflow, r ...