转自:
http://www.java265.com/JavaCourse/202204/2748.html
下文笔者将讲述lastlastIndexOfSubList()方法的功能简介说明,如下所示:- <strong>lastlastIndexOfSubList()方法的功能:
- 返回一个int值
- 其值为给定源列表(src)中给定子列表(dest)的最后一次出现的起始索引,否则,当找不到搜索或列表为空时返回-1
- lastlastIndexOfSubList()方法的语法:
- public static int lastIndexOfSubList(List src, List dest);
- 参数:
- List src:源列表,在其中过滤给定列表(目的地)的最后一次出现
- List dest:要过滤给定源列表(src)的子列表的目标列表(目标)
- 注意事项:
- 1.lastIndexOfSubList()方法在jav</strong>a.util包中可用
- 2.lastIndexOfSubList()方法用于返回给定(目标)列表在给定源列表(src)中最后一次出现的起始索引
- 3.lastIndexOfSubList()方法是静态方法,因此可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会收到错误
- 在返回给定List(目标)的最后一次出现的索引时,lastIndexOfSubList()方法不会引发异常
复制代码 例:- package com.java265.other;
- import java.util.Collections;
- import java.util.LinkedList;
- import java.util.List;
- public class Test15 {
- /**
- * java265.com 示例 Collections.lastIndexOfSubList方法示例分享
- */
- public static void main(String[] args) {
- List src_l = new LinkedList();
- List dest_l = new LinkedList();
- // 通过使用add()方法是
- // 在链表src_l中添加元素
- src_l.add(11);
- src_l.add(22);
- src_l.add(33);
- src_l.add(44);
- src_l.add(55);
- // 通过使用add()方法是
- // 在链接列表dest_l中添加元素
- dest_l.add(88);
- dest_l.add(55);
- // 显示LinkedList-
- System.out.println("link_l: " + src_l);
- System.out.println("dest_l: " + dest_l);
- System.out.println();
- // 通过使用lastIndexOfSubList()方法是
- // 返回最后一次出现的起始索引
- // src_l中的dest_l-
- int index = Collections.lastIndexOfSubList(src_l, dest_l);
- // 显示索引
- System.out.println("Collections.lastIndexOfSubList(src_l,dest_l): " + index);
- }
- }
- ------运行以上代码,将输出以下信息------
- link_l: [11, 22, 33, 44, 55]
- dest_l: [88, 55]
- Collections.lastIndexOfSubList(src_l,dest_l): -1
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |