java中elements_java.util.Vector.elements()

描述

elements() 方法用来返回此向量的组件的枚举。返回的Enumeration对象将在类似索引位置生成此向量中的所有项。

声明

以下是java.util.Vector.elements()方法的声明

public Enumeration elements()

参数

不带任何输入参数

返回值

它返回此向量的组件的枚举。

异常

NA

实例

以下示例显示了java.util.Vector.elements()方法的用法。

package com.tutorialspoint;

import java.util.Vector;

import java.util.Enumeration;

public class VectorDemo {

public static void main(String[] args) {

// create an empty Vector vec with an initial capacity of 4

Vector vec = new Vector(4);

// use add() method to add elements in the vector

vec.add(4);

vec.add(3);

vec.add(2);

vec.add(1);

// adding elements into the enumeration

Enumeration e = vec.elements();

// let us print all the elements available in enumeration

System.out.println("Numbers in the enumeration are :- ");

while (e.hasMoreElements()) {

System.out.println("Number = " + e.nextElement());

}

}

}

让我们编译并运行上面的程序,这将产生以下结果。

Numbers in the enumeration are :-

Number = 4

Number = 3

Number = 2

Number = 1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值