日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

lastindexof方法_Java Vector lastIndexOf()方法与示例

發布時間:2023/12/1 java 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 lastindexof方法_Java Vector lastIndexOf()方法与示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

lastindexof方法

向量類別的lastIndexOf()方法 (Vector Class lastIndexOf() method)

Syntax:

句法:

public int lastIndexOf (Object ob);public int lastIndexOf (Object ob, int indices);
  • lastIndexOf() method is available in java.util package.

    lastIndexOf()方法在java.util包中可用。

  • lastIndexOf(Object ob) method is used to return the index of the last occurrence of the given element.

    lastIndexOf(Object ob)方法用于返回給定元素的最后一次出現的索引。

  • lastIndexOf(Object ob, int indices) method is used to find the index of the last occurrence of the given object in this Vector and searching starts at the given indices.

    lastIndexOf(Object ob,int index)方法用于查找此Vector中給定對象最后一次出現的索引,并從給定索引開始搜索。

  • These methods may throw an exception at the time of returning an index.

    這些方法在返回索引時可能會引發異常。

    IndexOutOfBoundsException: This exception may throw when the given parameter is not in a range.

    IndexOutOfBoundsException :如果給定參數不在范圍內,則可能引發此異常。

  • These are non-static methods and it is accessible with class objects and if we try to access these methods with the class name then we will get an error.

    這些是非靜態方法,可通過類對象訪問,如果嘗試使用類名訪問這些方法,則會收到錯誤消息。

Parameter(s):

參數:

  • In the first case, lastIndexOf(Object ob)

    在第一種情況下, lastIndexOf(Object ob)

    • Object ob – represents the object for which the last occurrence element index to be returned.
    • 對象ob –代表要為其返回最后一個出現元素索引的對象。
  • In the first case, lastIndexOf (Object ob, int indices)

    在第一種情況下, lastIndexOf(對象ob,int索引)

    • Object ob – represents the object for which the last occurrence element index to be returned.
    • 對象ob –代表要為其返回最后一個出現元素索引的對象。
    • int indices – represents the index of searching starts.
    • int index –表示搜索開始的索引。

Return value:

返回值:

In both the cases, the return type of the method is int - it gets the index of the last occurrence of the given object when exists otherwise it returns -1.

在這兩種情況下,方法的返回類型均為int-它在存在時獲取給定對象最后一次出現的索引,否則返回-1。

Example:

例:

// Java program to demonstrate the example // of lastIndexOf() method of Vectorimport java.util.*;public class LastIndexOfVector {public static void main(String[] args) {// Instantiates a vector object Vector < String > v = new Vector < String > (10);// By using add() method is to add// the elements in vectorv.add("C");v.add("C++");v.add("SFDC");v.add("C++");v.add("JAVA");//Display VectorSystem.out.println("v: " + v);// By using lastIndexOf(object) method is used// to return the index of last occurrence of the// given objectSystem.out.println("v.lastIndexOf(C++): " + v.lastIndexOf("C++"));// By using lastIndexOf(object, indices) method is used// to return the index of last occurrence of the// given object and searching starts from the // given indicesSystem.out.println("v.lastIndexOf(C++,4): " + v.lastIndexOf("C++", 4));} }

Output

輸出量

v: [C, C++, SFDC, C++, JAVA] v.lastIndexOf(C++): 3 v.lastIndexOf(C++,4): 3

翻譯自: https://www.includehelp.com/java/vector-lastindexof-method-with-example.aspx

lastindexof方法

總結

以上是生活随笔為你收集整理的lastindexof方法_Java Vector lastIndexOf()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。