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)的更多相关文章

  1. Generics and Collection (2)

    Integer is a subtype of NumberDouble is a subtype of NumberArrayList<E> is a subtype of List&l ...

  2. Java中Generics的使用

    1.Java的Generics与C++的Template由于Java的Generics设计在C++的Template之后,因此Java的Generics设计吸取Template的很多经验和教训.首先, ...

  3. 最佳新秀Java(22)——再次了解泛型

    仿制药Java SE 1.5新功能.通用自然是参数化类型.即操作数据类型被指定为一个参数.这样的参数类型可以在课堂上使用.创建的接口和方法,他们被称为通用类..泛型方法. Java语言引入泛型的优点是 ...

  4. Swift 学习笔记(四)

    116.使用可选链式调用代替强制展开 通过在想调用的属性.方法.或下标的可选值(optional value)后面放一个问号(?),可以定义一个可选链.这一点很像在可选值后面放一个叹号(!)来强制展开 ...

  5. 菜鸟学Java(二十二)——重新认识泛型

    泛型是Java SE 1.5的新特性,泛型的本质是参数化类型,也就是说所操作的数据类型被指定为一个参数.这种参数类型可以用在类.接口和方法的创建中,分别称为泛型类.泛型接口.泛型方法. Java语言引 ...

  6. 菜鸟学Java(二十二)——又一次认识泛型

    泛型是Java SE 1.5的新特性,泛型的本质是參数化类型,也就是说所操作的数据类型被指定为一个參数.这样的參数类型能够用在类.接口和方法的创建中,分别称为泛型类.泛型接口.泛型方法. Java语言 ...

  7. 12.Generics

    benifit: 1.make developers extremely productive is code reuse, which is the ability to derive a clas ...

  8. JDK1.5新特性(六)……Generics

    概述 Generics - This long-awaited enhancement to the type system allows a type or method to operate on ...

  9. thinking in java Generics Latent typing

    The beginning of this chapter introduced the idea of writing code that can be applied as generally a ...

随机推荐

  1. CentOS7:安装Puppet

    环境说明: 192.168.154.137 master.localdomain #Puppet Server 192.168.154.138 agent1.localdomain #Puppet A ...

  2. Win 8.1 Pro &amp;MSSQLServer 2014 Enterprise

    给Thinkpad E431 安装上 Windows 8.1 Pro 之后,一直都安装不上 MSSQLServer 2005 DEV / ENT,2008 ENT / STAND, 2008 R2  ...

  3. 在Excel中将数字转换为大写

    123.09 = 壹佰贰拾叁元零玖分 =SUBSTITUTE(SUBSTITUTE(IF(G10<0,"負","")&TEXT(TRUNC(ABS ...

  4. 查找SQL SERVER被锁的表和解决方法

    查找数据库中被锁表代码: select   request_session_id   spid,OBJECT_NAME(resource_associated_entity_id) tableName ...

  5. setContentType、setCharacterEncoding、pageEncoding和contentType

    request.setCharacterEncoding()是设置从request中取得的值或从数据库中取出的值 response.setContentType("text/html;cha ...

  6. Junit3断言

    在Robotium自动化测试的过程中,发现没有断言的脚本是没有意义的,现整理Junit3和Junit4的断言,供日后查阅. http://junit.org/ Junit3断言API: http:// ...

  7. ajax options

    非同一域名的ajax post请求,浏览器会自动发送http options的请求检查是否允许跨域访问

  8. JS面向对象的程序设计

    面向对象的语言有一个标志,即拥有类的概念,抽象实例对象的公共属性与方法,基于类可以创建任意多个实例对象,一般具有封装.继承.多态的特性!但JS中对象与纯面向对象语言中的对象是不同的,ECMA标准定义J ...

  9. CString转string

    如题,找了半天... //CString转string USES_CONVERSION; CString temp; temp = _T("kjdsaflkjdlfkj"); ch ...

  10. C语言Notebook

    int *pointer=NULL    /*指针变量一定要赋初值*/pritnf("Pointer' address is:%p",&pointer);  /*打印指针变 ...