目录

E get(int index)

描述 (Description)

get(int index)方法用于返回此Vector中指定index位置的元素。

声明 (Declaration)

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

public E get(int index)

参数 (Parameters)

index - 这是要返回的元素的索引位置

返回值 (Return Value)

方法调用返回指定索引处的对象。

异常 (Exception)

ArrayIndexOutOfBoundsException - 如果访问的索引/位置超出范围,则抛出此异常。

例子 (Example)

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

package com.iowiki;
import java.util.Vector;
public class VectorDemo {
   public static void main(String[] args) {
      // create an empty Vector vec with an initial capacity of 4      
      Vector<Integer> vec = new Vector<Integer>(4);
      // use add() method to add elements in the vector
      vec.add(4);
      vec.add(3);
      vec.add(2);
      vec.add(1);
      // let us get the 3rd element of the vector
      System.out.println("Third element is :"+vec.get(3));
   }
}

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

Third element is :1
↑回到顶部↑
WIKI教程 @2018