java vector_Java Vector lastElement()方法与示例
java vector
向量類的lastElement()方法 (Vector Class lastElement() method)
lastElement() method is available in java.util package.
lastElement()方法在java.util包中可用。
lastElement() method is used to return the last element of this Vector.
lastElement()方法用于返回此Vector的最后一個元素。
lastElement() 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.
lastElement()方法是一種非靜態(tài)方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。
lastElement() method may throw an exception at the time of returning the last element.
返回最后一個元素時, lastElement()方法可能會引發(fā)異常。
NoSuchElementException: This exception may throw when this Vector is "empty".
NoSuchElementException :如果此Vector為“空”,則可能引發(fā)此異常。
Syntax:
句法:
public Element lastElement();Parameter(s):
參數(shù):
It does not accept any parameter.
它不接受任何參數(shù)。
Return value:
返回值:
The return type of the method is Element, it returns the last element of this Vector.
方法的返回類型為Element ,它返回此Vector的最后一個元素。
Example:
例:
// Java program to demonstrate the example // of Element lastElement() method of Vector import java.util.*;public class LastElementOfVector {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 vv.add("C");v.add("C++");v.add("JAVA");// Display VectorSystem.out.println("v: " + v);// By using lastElement() method is// to return the last element exists Object ele = v.lastElement();// Display Last ElementSystem.out.println("v.lastElement(): " + ele);} }Output
輸出量
v: [C, C++, JAVA] v.lastElement(): JAVA翻譯自: https://www.includehelp.com/java/vector-lastelement-method-with-example.aspx
java vector
總結(jié)
以上是生活随笔為你收集整理的java vector_Java Vector lastElement()方法与示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ups一直响是什么原因_UPS的完整形式
- 下一篇: nextboolean()_Java R