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 Vector
import 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 vector
v.add("C");
v.add("C++");
v.add("SFDC");
v.add("C++");
v.add("JAVA");
//Display Vector
System.out.println("v: " + v);
// By using lastIndexOf(object) method is used
// to return the index of last occurrence of the
// given object
System.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 indices
System.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方法

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/378676.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378676.shtml
英文地址,請注明出處:http://en.pswp.cn/news/378676.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

李開復:微博的價值在哪里

導讀&#xff1a;微博可以改變社會現象&#xff0c;可以傳播信息&#xff0c;可以幫助你成長&#xff0c;可以發出你的聲音。它讓我們能夠人人成為記者&#xff0c;讓每一個轉發的人都變成了一個編輯 很多人問微博是搶了誰的生意&#xff0c;開心網還是人人網&#xff1f;其實它…

mysql 任務計劃 /etc/cron.d_Linux /etc/cron.d增加定時任務

一般情況下我們添加計劃任務時&#xff0c;都是直接修改/etc/crontab。但是&#xff0c;不建議這樣做&#xff0c;/etc/cron.d目錄就是為了分項目設置計劃任務而創建的。例如&#xff0c;增加一項定時的備份任務&#xff0c;我們可以這樣處理&#xff1a;在/etc/cron.d目錄下新…

19-Harris角點檢測

角點檢測顧名思義&#xff0c;就是對類似頂點的檢測&#xff0c;與邊緣有所區別 邊緣可能在某一方向上變化不是特別明顯&#xff0c;但角點在任何方向上變換都很明顯 cv2.cornerHarris(img,blockSize,ksize,k) cv2.cornerHarris(gray,2,3,0.04) 參數一&#xff1a;img&#xff…

微機原理——指令系統——算數運算指令(ADD、ADC、SUB、SBB、INC、DEC、NEG、CMP、MUL、IMUL、DIV、IDIV、CBW、CWD、BCD調整)

博主聯系方式&#xff1a; QQ:1540984562 QQ交流群&#xff1a;892023501 群里會有往屆的smarters和電賽選手&#xff0c;群里也會不時分享一些有用的資料&#xff0c;有問題可以在群里多問問。 算數運算指令1、加減法指令ADD、ADC 、SUB 、SBB 和增量減量指令INC、DEC、NEGADD…

linux系統出現Too many open files 錯誤、linux too many open files

故障一、linux too many open files linux系統出現Too many open files 錯誤&#xff0c;這是因為文件描述符大小不夠&#xff0c;或者有不正常的網絡連接(Socket也是一種特殊的文件)、文件IO沒有關閉并釋放出文件描述符&#xff08;文件句柄&#xff0c;File Operator&#xf…

精通init ramfs構建

一、init ramfs是什么   在2.6版本的linux內核中&#xff0c;都包含一個壓縮過的cpio格式的打包文件。當內核啟動時&#xff0c;會 從這個打包文件中導出文件到內核的rootfs文件系統&#xff0c;然后內核檢查rootfs中是否包含有init文件&#xff0c;如果有則執行它&#xff0…

python 示例_帶有示例的Python date isocalendar()方法

python 示例Python date.isocalendar()方法 (Python date.isocalendar() Method) date.isocalendar() method is used to manipulate objects of date class of module datetime. date.isocalendar()方法用于操作模塊datetime的日期類的對象。 It uses a date class object a…

mysql 函數重載_[賦值]函數,變量,重載 ,_第1頁_169IT

[java/j2ee] java實現簡單的給sql語句賦值的示例代碼本身很簡單。拼接sql的時候&#xff1f;不好數&#xff0c;簡單的用來賦值。代碼如下:/** * TODO 循環賦值,缺少的類型可隨時添加 * author Lucius * param pt * param list * throws SQLException */ public static…

20-SIFT算法

import cv2 import numpy as np from matplotlib import pyplot as pltdef show_photo(name,picture):#圖像顯示函數cv2.imshow(name,picture)cv2.waitKey(0)cv2.destroyAllWindows()img cv2.imread(E:\Jupyter_workspace\study\data/cfx.png) gray cv2.cvtColor(img,cv2.COL…

Opencv——寫入或讀取數據到XML或YAML文件

什么是XML、YAML文件 XML(eXtensible Markup Language)是一種元標記語言。所謂“原標記”&#xff0c;就是開發者可以根據自身需要定義的標記&#xff0c;任何滿足XML命名規則的名稱都可以標記。此外&#xff0c;XML是一種語義/結構化語言&#xff0c;它描述了文檔的結構和語義…

mysql 遷移 nosql_從關系型Mysql到Nosql HBase的遷移實踐

2013年11月22-23日&#xff0c;作為國內唯一專注于hadoop技術與應用分享的大規模行業盛會&#xff0c;2013 Hadoop中國技術峰會(China Hadoop Summit 2013)于北京福朋喜來登集團酒店隆重舉行。來自國內外各行業領域的近千名CIO、CTO、架構師、IT經理、咨詢顧問、工程師、Hadoop…

Oracle EBS數據定義移植工具:FNDLOAD

在實際的EBS二次開發中&#xff0c;我們經常會碰到需要在各個環境之間移植二次開發的程序對象以及數據定義&#xff0c;如在EBS二次開發中并發請求的定義會涉及到&#xff1a;可執行、并發程序、值集、請求組等的定義&#xff0c;定義需要從開發環境、測試環境、UAT環境一直到正…

21-特征匹配方法(Brute-Force蠻力匹配)

Brute-Force蠻力匹配 cv2.BFMatcher(crossCheck True) crossCheck表示兩個特征點相互匹配 例如A中的第i個特征點與B中的第j個特征點最近&#xff0c;并且B中的第j個特征點到A中的第i個特征點也是 NORM_L2&#xff1a;歸一化數組的(歐幾里得距離)&#xff0c;如果其他特征計算…

weakhashmap_Java WeakHashMap values()方法與示例

weakhashmapWeakHashMap類values()方法 (WeakHashMap Class values() method) values() method is available in java.util package. values()方法在java.util包中可用。 values() method is used to get the values that exist in this map to be viewed in a collection. val…

Opencv——幾何空間變換(仿射變換和投影變換)

幾何空間變換【1】幾何變換&#xff08;空間變換&#xff09;簡述【2】變換矩陣知識簡述齊次坐標的概念幾何運算矩陣【3】圖像的仿射變換1、平移變換2、比例縮放3、旋轉4、對稱變換&#xff08;不做展示&#xff09;1、關于X軸變換2、關于Y軸變換3、關于直線YX變換4、關于直線Y…

用于主題檢測的臨時日志(e1784e6f-037e-45de-bad1-8bbc239818ee - 3bfe001a-32de-4114-a6b4-4005b770f6d7)...

這是一個未刪除的臨時日志。請手動刪除它。(578392f7-2207-4b01-b36d-c483f0699988 - 3bfe001a-32de-4114-a6b4-4005b770f6d7)轉載于:https://www.cnblogs.com/Fly-sky/archive/2011/03/03/1969850.html

probuffer java_Protocol Buffer的使用

Probotbuf簡介在網絡通信和通用數據交換等應用場景中經常使用的技術是 JSON 或 XML&#xff0c;這兩種技術常被用于數據的結構化呈現和序列化。我們可以從兩個方面來看JSON 和 XML與protobuf的異同&#xff1a;一個是數據結構化&#xff0c;一個是數據序列化。這里的數據結構化…

根據DbSchema生成代碼2

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; using System.Threading; using System.IO; using Rocky;namespace Rocky.CodeBuilder {public class DbBuilder : Disposable{#region 字段public even…

22-隨機抽樣一致算法RANSAC

隨機抽樣一致算法(Random sample consensus&#xff0c;RANSAC) 看似復雜&#xff0c;其基本思想就是&#xff1a;隨機選取倆點&#xff0c;然后連接&#xff0c;給定一個容忍范圍&#xff0c;在這個范圍內的點越多越好&#xff0c;然后不斷的迭代進行找兩點之間容忍范圍內點最…

treeset比較器_Java TreeSet比較器()方法與示例

treeset比較器TreeSet類的compare()方法 (TreeSet Class comparator() method) comparator() method is available in java.util package. 比較器()方法在java.util包中可用。 comparator() method is used to get the Comparator object based on customizing order the eleme…