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方法

lastindexof方法_Java Vector lastIndexOf()方法与示例相关推荐

  1. fileitem方法_Java FileItem.write方法代码示例

    本文整理汇总了Java中org.apache.commons.fileupload.FileItem.write方法的典型用法代码示例.如果您正苦于以下问题:Java FileItem.write方法 ...

  2. java getitem方法_Java Datasource.getItem方法代碼示例

    本文整理匯總了Java中com.haulmont.cuba.gui.data.Datasource.getItem方法的典型用法代碼示例.如果您正苦於以下問題:Java Datasource.getI ...

  3. java findpage 方法_Java Strings.isNotBlank方法代碼示例

    本文整理匯總了Java中de.invesdwin.util.lang.Strings.isNotBlank方法的典型用法代碼示例.如果您正苦於以下問題:Java Strings.isNotBlank方 ...

  4. java的scanner的方法_Java Scanner reset()方法

    Java Scanner reset()方法 java.util.Scanner.reset() 方法重置该扫描仪.重设scanner 丢弃所有的这些可能已被useDelimiter(java.uti ...

  5. java方法重载和重载方法_Java 8的方法参考进一步限制了重载

    java方法重载和重载方法 方法重载一直是一个充满喜忧参半的话题. 我们已经在博客上介绍了它,并介绍了几次警告: 您会后悔对Lambdas应用重载! 保持干燥:方法重载 为什么每个人都讨厌操作员超载 ...

  6. java方法重载和重载方法_Java中的方法重载

    java方法重载和重载方法 The concept of Method Overloading in Java is where a class can have multiple methods w ...

  7. c调用其他类的方法_Java 的 Native 方法——今天又进步了

    1. 简介 1.1 个人理解 初次遇见 native 是在 java.lang.String 源码中的一个 intern 方法: public native String intern(); 因为还是 ...

  8. java中math的方法_Java Math所有方法

    首页 > 基础教程 > 常用类 > 常用 Number & Math类 Java Math所有方法 Math类包含完成基本数学函数所需的方法.这些方法分为三类:三角函数方法. ...

  9. java中方法_java中的方法

    java中的方法 java作为一种面向对象的语言,具有以下特性:继承.封装.多态.抽象.类.对象.实例.方法和重载. 今天讲解的是java方法的概念. 什么是方法? java方法是语句的集合,他们在一 ...

最新文章

  1. Java中的50个关键字
  2. 数据派研究组招募 | 寻找最志同道合的你!
  3. python输入文件名读取文件_[Python] python3 文件操作:从键盘输入、打开关闭文件、读取写入文件、重命名与删除文件等...
  4. Easyfi遭受黑客攻击,被盗600万美元稳定币以及298万个EASY代币
  5. 20155230 2016-2017-2《Java程序设计》课程总结
  6. 关于微信wx.getUserInfo使用不了的问题
  7. Windows下误删文件解决办法
  8. 完美卸载SQL Server 2008的方案
  9. 单反相机坏点和噪点测试软件,单反相机测试坏点和噪点的软件
  10. excel2007如何增加控件?
  11. [GIS热点] 3S技术集成-新技术革命下集成模式
  12. Mapreduce统计
  13. Java校招面经_校招面经:阿里天猫Java后台开发面试历程
  14. Python 爬虫下载喜马拉雅音频文件
  15. 阿里云服务 - Java实现短信验证码发送 --(完整教程)
  16. PaddleOCR新发版v2.2:开源版面分析与轻量化表格识别
  17. Shader学习的基础知识( 三十一)水波效果
  18. 基于WEB的水果电商平台
  19. Linux系统管理实践(7):网络配置
  20. 如何在Psim中使用C语言实现LLC闭环仿真

热门文章

  1. ztree java 增删改_Ztree实现增删改查
  2. 微软MS10-046漏洞的利用
  3. 计算机组装报告文档,计算机组装报告.doc.docx
  4. axios队列 vue_vue axios全攻略
  5. java静态方法获取对象_JavaPowerMockito模拟单个静态方法和返回对象
  6. http请求post,返回excel文件,并接收
  7. 为Kindeditor控件添加图片自动上传功能
  8. 初学servlet之使用web.xml配置
  9. elasticsearch启动错误解决
  10. Regular Exprassion--正则表达式基础