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.mzph.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…