zoukankan      html  css  js  c++  java
  • Generics and Collection (1)

     1 public static void main(String args[]) {
     2         List ints = Arrays.asList(new Integer[]{new Integer(1), new Integer(3)});
     3         int s =0;
     4         for(Iterator it = ints.iterator(); it.hasNext();)
     5         {
     6             int n = ((Integer)it.next()).intValue();
     7             s+=n;
     8         }
     9         System.out.println(s);
    10     }
    public static void main(String args[]) {
            List<Integer> ints = Arrays.asList(1,2,3);
            int s = 0;
            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(0) +words.get(1);        
            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);
        }
    }
  • 相关阅读:
    float浮动
    数据库基础操作
    Python re 模块
    I/O模型的使用
    函数形参与实参
    内置函数重写_运算符重载
    导入模块_导入包_标准库模块
    异常处理
    闭包
    函数式编程
  • 原文地址:https://www.cnblogs.com/Ring1981/p/4471808.html
Copyright © 2011-2022 走看看