java 方法 示例

集合类lastIndexOfSubList()方法 (Collections Class lastIndexOfSubList() method)

  • lastIndexOfSubList() method is available in java.util package.

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

  • lastIndexOfSubList() method is used to return the starting index of the last occurrence of the given (dest) list within the given source list (src).

    lastIndexOfSubList()方法用于返回给定源列表( src )中给定( dest )列表最后一次出现的起始索引。

  • lastIndexOfSubList() method is a static method, so it is accessible with the class name and if we try to access the method with the class object then we will not get an error.

    lastIndexOfSubList()方法是一个静态方法,因此可以使用类名进行访问,并且如果尝试使用类对象访问该方法,则不会收到错误。

  • lastIndexOfSubList() method does not throw an exception at the time of returning the index of the last occurrence of the given List (dest).

    在返回给定List( dest )的最后一次出现的索引时, lastIndexOfSubList()方法不会引发异常。

Syntax:

句法:

    public static int lastIndexOfSubList(List src, List dest);

Parameter(s):

参数:

  • List src – represents the source list in which to filter the last occurrence of the given list(dest).

    List src –表示源列表,在其中过滤给定列表( dest )的最后一次出现。

  • List dest – represents the targeted list(dest) to filter sublist of the given source list(src).

    列表目标 –表示要过滤给定源列表( src )的子列表的目标列表( dest )。

Return value:

返回值:

The return type of this method is int, it returns starting index of the last occurrence of the given sublist (dest) within the given source list(src) otherwise it returns -1 when no search found or list empty.

此方法的返回类型为int ,它返回给定源列表( src )中给定子列表( dest )的最后一次出现的起始索引,否则,当找不到搜索或列表为空时返回-1。

Example:

例:

// Java program is to demonstrate the example
// of int lastIndexOfSubList() of Collections
import java.util.*;
public class LastIndexOfSubList {public static void main(String args[]) {// Instantiate a LinkedList
List src_l = new LinkedList();
List dest_l = new LinkedList();
// By using add() method is to
// add elements in linked list src_l
src_l.add(10);
src_l.add(20);
src_l.add(30);
src_l.add(40);
src_l.add(50);
// By using add() method is to
// add elements in linked list dest_l
dest_l.add(40);
dest_l.add(50);
// Display LinkedList
System.out.println("link_l: " + src_l);
System.out.println("dest_l: " + dest_l);
System.out.println();
// By using lastIndexOfSubList() method is to
// return the starting index of last occurrence
// of dest_l in src_l
int index = Collections.lastIndexOfSubList(src_l, dest_l);
//Display index
System.out.println("Collections.lastIndexOfSubList(src_l,dest_l): " + index);
}
}

Output

输出量

link_l: [10, 20, 30, 40, 50]
dest_l: [40, 50]Collections.lastIndexOfSubList(src_l,dest_l): 3

翻译自: https://www.includehelp.com/java/collections-lastindexofsublist-method-with-example.aspx

java 方法 示例

java 方法 示例_Java集合的lastlastIndexOfSubList()方法和示例相关推荐

  1. java集合示例_Java集合的addAll()方法和示例

    集合类addAll()方法addAll()方法在java.lang包中可用. addAll()方法用于将所有给定元素(ele)放入给定集合(co). addAll()方法是一个静态方法,可以使用类名进 ...

  2. java 静态缓存示例_Java 9 JShell示例:集合静态工厂方法

    java 静态缓存示例 这篇文章继续从My My Java 9 Features博客文章中探索Java9功能. 在这里,我们在List,Set和Map接口中试验Java9 Collections静态工 ...

  3. java 方法 示例_Java集合syncedSortedSet()方法与示例

    java 方法 示例 集合类SynchronizedSortedSet()方法 (Collections Class synchronizedSortedSet() method) synchroni ...

  4. Java 9 JShell示例:集合静态工厂方法

    这篇文章继续了My My Java 9 Features博客文章中对Java9功能的探索. 在这里,我们在List,Set和Map接口中试验Java9 Collections静态工厂方法. 集合静态工 ...

  5. java parsefloat 误差_Java Float类parseFloat()方法与示例

    Float类parseFloat()方法parseFloat()方法在java.lang包中可用. parseFloat()方法用于返回与给定String表示形式相对应的float值,换句话说,我们可 ...

  6. java getmethod类_Java Class类 getMethod()方法及示例

    Class类getMethod()方法getMethod()方法在java.lang包中可用. getMethod()方法用于返回Method对象,这些对象指示该类的给定公共方法或由此Class对象表 ...

  7. java isempty用法_Java ArrayList isEmpty() 使用方法及示例

    Java ArrayList isEmpty() 使用方法及示例 Java ArrayList isEmpty()方法用于检查arraylist是否为空. 该isEmpty()方法的语法为: arra ...

  8. java newinstance 包_Java Class类 newInstance()方法及示例

    Class类newInstance()方法newInstance()方法在java.lang包中可用. newInstance()方法用于创建此Class对象表示的类的新实例. newInstance ...

  9. java中intvalue方法作用_Java Integer类intValue()方法及示例

    整数类intValue()方法intValue()方法在java.lang包中可用. intValue()方法用于返回此Integer对象表示的值,该值转换为int类型(通过强制转换). intVal ...

最新文章

  1. 行业|又一家明星机器人公司倒掉:曾是全球机器人技术50强,主打性价比AI机械臂...
  2. 为什么事情执行不下去?
  3. 关于移动应用APP数据安全的一点见解
  4. android 打包相关问题记录
  5. 1.Hello,Python
  6. JVM类加载机制_字节码执行引擎_Java内存模型
  7. cmake,CMakeLists.txt,make,makefile的关系
  8. (组合数学笔记)格点路径问题分析求解
  9. JDK1.8 HashSet
  10. STM32工作笔记0057---外部中断实验
  11. 携程第二场预赛 1003:位图像素的颜色(水题,判断点是否在矩形内)
  12. 腾讯的KDD competition
  13. Atitit 计算机系统结构 计算机系统结构 Cpu 存储 cache 指令系统 目录 Line 56: 第2章指令系统设计 指令格式 寻址方式 1 Line 64: 第3章CPU及其实现
  14. IT项目建议书及可行性研究报告撰写格式
  15. 电脑/手机怎么查看连接的wifi的密码
  16. 如何解决DNS解析错误
  17. 20211218:口罩数据汇总
  18. 笔记本电脑开启热点后电脑无法上网问题——亲测可行【06-17】
  19. Google BERT 中文应用之《红楼梦》中对话人物提取
  20. ORM是什么? ORM框架是什么?

热门文章

  1. python自定义模块和三方模块_python基础知识8——模块1——自定义模块和第三方开源模块...
  2. 三万字速通SSM框架入门知识点,快速上手CRUD
  3. 【Java从入门到头秃专栏 4】语法篇(三) :字符串 数组
  4. C++ 判断类是否有某变量
  5. 微软希望每个人有自己的人工智能朋友
  6. Mac 设置 NDK
  7. os和shutil模块
  8. 关于JAVA中的synchronized,一段不错的解释...
  9. KMP POJ 2752 Seek the Name, Seek the Fame
  10. PHP安装ZIP扩展