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 Collectionsimport 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_lsrc_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_ldest_l.add(40);dest_l.add(50);// Display LinkedListSystem.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_lint index = Collections.lastIndexOfSubList(src_l, dest_l);//Display indexSystem.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()方法和示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JavaScript中的If和Else语
- 下一篇: Java中这7个方法,一不小心就用错了!