博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
集合类接口
阅读量:4604 次
发布时间:2019-06-09

本文共 2290 字,大约阅读时间需要 7 分钟。

集合类包括;: vector ,e

View Code
import java.util.*;public class TestCollection {    /**     * Method main     *     *     * @param args     *     */    public static void main(String[] args) {        Arraylist v=new Arraylist();        System.out.println("please enter number:");        while(true)        {           int b=System.in.read();           //判断如果回车则字符输入完毕         if(b=='\r'||b=='\n')         {               break;         }         else{             int num=b-'0';// 这个地方需要关注下             v.add(new Integer(num))              v.addElement(new Integer(num)); //存储到vector中,用增加元素             //需要的是对象,int不是对象,所以用Interger对象包装数组       //addElement 是vector的方法   add()是arraylist的方法,其没有addElement方法                    }        }        int sum=0;    Iterator e =    v.Iterator();// 返回enumeration对象 // while(e.hasMoreElements()) while(e.hasNext())      {      //    Inerger intobj=(Integer)e.nextElement();      Inerger intobj=(Integer)e.next();          sum+=intobj.intValue();      }          System.out.println(sum);    // 没有对象时候    //这个方法可以取出enumeration的所有整数对象,enumeration    //有一个指示器,   返回指示器正指向的那个元素对象,然后把指示器指向    //下一个元素对象  nextElement 是object型,需要转换    }}

 Enumeration ,vector,Arraylist,Collection,iterator,set,list

collection  各元素间没有指定的顺序,允许重复元素和多个null

set         

 

import java.util.*;public class TestVector {    /**     * Method main     *     *     * @param args     *     */    public static void main(String[] args) {        Vector v=new Vector();        System.out.println("please enter number:");        while(true)        {           int b=System.in.read();           //判断如果回车则字符输入完毕         if(b=='\r'||b=='\n')         {               break;         }         else{             int num=b-'0';// 这个地方需要关注下             v.addElement(new Integer(m)); //存储到vector中,用增加元素             //需要的是对象,int不是对象,所以用Interger对象包装数组             }        }        int sum=0;    Enumeration e =    v.elements();// 返回enumeration对象  while(e.hasMoreElements())      {          Integer intobj=(Integer)e.nextElement();          sum+=intobj.intValue();      }          System.out.println(sum);    // 没有对象时候    //这个方法可以取出enumeration的所有整数对象,enumeration    //有一个指示器,   返回指示器正指向的那个元素对象,然后把指示器指向    //下一个元素对象  nextElement 是object型,需要转换    }}

 

转载于:https://www.cnblogs.com/xiao-wei-wei/archive/2012/06/02/2532036.html

你可能感兴趣的文章
2017.10.4 国庆清北 D4T2 正方形
查看>>
java链表实现
查看>>
<context:component-scan>子标签:<context:include-filter>和<context:exclude-filter>使用时要注意的地方...
查看>>
Java基础——工厂模式
查看>>
Oracle卸载
查看>>
ios中scrollView基本用法
查看>>
Python--网络编程-----socket介绍
查看>>
android的Timer方法
查看>>
nodejs入门
查看>>
DT大数据梦工厂 第80讲
查看>>
网页游戏制作
查看>>
温故知新(5)——组合模式
查看>>
消息队列Java的简单实现
查看>>
C#语法之Linq查询基础二
查看>>
敏捷开发智慧敏捷系列之三:做不做架构设计?
查看>>
MMSEG 中文分词算法 翻译
查看>>
Java求职实战之继承和多态
查看>>
手机Fildder抓包_监控应用请求
查看>>
【SoftwareTesting】Homework2
查看>>
Java常见笔试、面试题目深度剖析
查看>>