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 ...
随机推荐
- C#位操作(转)
在C#中可以对整型运算对象按位进行逻辑运算.按位进行逻辑运算的意义是:依次取被运算对象的每个位,进行逻辑运算,每个位的逻辑运算结果是结果值的每个位.C#支持的位逻辑运算符如表2.9所示. 算符号 意义 ...
- mysql on Mac OS
在新买的macbook pro15上安装了mysql,发现2个问题 一个是workbench基本无法正常退出,都要force quit 第二是我正常通过workbench连接后,查看系统log,会发现 ...
- log4cplus 在配置文件中设置文件路径,程序自动创建目录,且在日志文件前按日期创建相应的目录
#include <string> #include <cstdio> #include <log4cplus/logger.h> #include <log ...
- Mysql查询英文如何严格区分大小写?
1. 前提:在Mysql数据库中进行查询时,希望英文严格区分大小写.默认情况下是不区分大小写的.2. 演示如下:在数据库表emp中,job字段中存储的值有'Engineer',现在的情况是,下面的两句 ...
- 定位form光标行
In AX2009 if you call the research() method on a form passing true, the cursor position within a gri ...
- questasim仿真控制——breakpoint断点
在使用questasim或者modelsim仿真时,如果需要控制仿真时间长度,一般在vsim中使用 run xxxxms/us等命令. 但是有时候不好估计仿真多长时间才能得到所有希望观察的结果,这个时 ...
- Liunx 常用命令
Liunx 常用命令================================================================================ 1. 远程拷贝文件 ...
- C++设计模式-Flyweight享元模式
Flyweight享元模式 作用:运用共享技术有效地支持大量细粒度的对象. 内部状态intrinsic和外部状态extrinsic: 1)Flyweight模式中,最重要的是将对象分解成intrins ...
- c# 获取某日期所在周的第一天和最后一天
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace WyfC ...
- APNS 服务推送通知
1. 将app注册notification里面, 并从APNS上获取测试机的deviceToken. - (BOOL)application:(UIApplication *)application ...