java 方法 示例_Java集合的lastlastIndexOfSubList()方法和示例

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值