java vector
向量類elements()方法 (Vector Class elements() method)
elements() method is available in java.util package.
elements()方法在java.util包中可用。
elements() method is used to get an enumeration of the elements that exist in this Vector.
elements()方法用于獲取此Vector中存在的元素的枚舉。
elements() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
elements()方法是一種非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。
elements() method does not throw an exception at the time of returning elements in an Enumeration view.
在枚舉視圖中返回元素時, elements()方法不會引發異常。
Syntax:
句法:
public Enumeration elements();
Parameter(s):
參數:
It does not accept any parameter.
它不接受任何參數。
Return value:
返回值:
The return type of the method is Enumeration, it returns an Enumeration that contain all objects of this Vector.
該方法的返回類型為Enumeration ,它返回一個Enumeration,其中包含此Vector的所有對象。
Example:
例:
// Java program to demonstrate the example
// of Enumeration elements() method
// of Vector
import java.util.*;
public class ElementsOfVector {
public static void main(String[] args) {
// Instantiates a Vector object with
// initial capacity of "10"
Vector < String > v = new Vector < String > (10);
// By using add() method is to add the
// elements in this v
v.add("C");
v.add("C++");
v.add("JAVA");
// Display Vector
System.out.println("v: " + v);
// By using elements() method is to
// get all the elements into an Enumeration
// and display it with the help of for loop
System.out.println("Enumeration: ");
for (Enumeration en = v.elements(); en.hasMoreElements();)
System.out.println(en.nextElement());
}
}
Output
輸出量
v: [C, C++, JAVA]
Enumeration:
C
C++
JAVA
翻譯自: https://www.includehelp.com/java/vector-elements-method-with-example.aspx
java vector