日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

java字符串删掉子串_如何从Java中的列表中删除子列表?

發(fā)布時(shí)間:2025/3/11 java 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java字符串删掉子串_如何从Java中的列表中删除子列表? 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

java字符串刪掉子串

從列表中刪除子列表 (Removing SubList from a List)

Suppose, we have a list of few elements like this,

假設(shè)我們列出了一些這樣的元素,

list = [10,20,30,40,50]

From the list, we have to delete a sub list between sourcing_index (inclusive) and destinating_index (exclusive).

從列表中,我們必須刪除sourcing_index (包括)和destinating_index (排除)之間的子列表。

This can be done by two ways,

這可以通過兩種方式完成:

  • By Using subList(int sourcing_index, int destinating_index) and clear() method of interface.

    通過使用接口的subList(int sourcing_index,int destinating_index)和clear()方法。

  • By Using removeRange(int sourcing_index, int destinating_index) method of List interface.

    通過使用List接口的removeRange(int sourcing_index,int destinating_index)方法。

  • subList(int sourcing_index,int destinating_index)和clear()的列表 (subList(int sourcing_index, int destinating_index) and clear() of List)

    This method is available in List interface.

    在列表界面中可以使用此方法。

    Syntax:

    句法:

    subList(int sourcing_index, int destinating_index);

    We pass two parameters in the method of the List,

    我們?cè)贚ist方法中傳遞兩個(gè)參數(shù),

    • Sourcing_index is the selection of the starting point of the subList.

      Sourcing_index是子列表起點(diǎn)的選擇。

    • Destinating_index is the selection of the ending point of the subList.

      Destinating_index是對(duì)子列表終點(diǎn)的選擇。

    Example:

    例:

    import java.util.*;public class DeleteSublist {public static void main(String[] args) {LinkedList list = new LinkedList();// use add() method to add elements in the list list.add(10);list.add(20);list.add(30);list.add(40);list.add(50);// Current list OutputSystem.out.println("The Current list is:" + list);// We will delete sublist by using subList(int,int) // and clear() method of List.list.subList(2, 4).clear();// New list Output after implementation of // subList() and clear() method.System.out.println("The New list is:" + list);} }

    Output

    輸出量

    E:\Programs>javac DeleteSublist.javaE:\Programs>java DeleteSublist The Current list is:[10, 20, 30, 40, 50] The New list is:[10, 20, 50]

    removeRange(int sourcing_index,int destinating_index) (removeRange(int sourcing_index, int destinating_index))

    This method is available in List interface.

    在列表界面中可以使用此方法。

    Syntax:

    句法:

    removeRange(int sourcing_index, int destinating_index);

    We pass two parameters in the method of the List,

    我們?cè)贚ist方法中傳遞兩個(gè)參數(shù),

    • Sourcing_index is the selection of the starting point of the subList.

      Sourcing_index是子列表起點(diǎn)的選擇。

    • Destinating_index is the selection of the ending point of the subList.

      Destinating_index是對(duì)子列表終點(diǎn)的選擇。

    Example:

    例:

    import java.util.*;public class DeleteSublist extends LinkedList {public static void main(String[] args) {DeleteSublist list = new DeleteSublist();// use add() method to add elements in the list list.add(10);list.add(20);list.add(30);list.add(40);list.add(50);// Current list OutputSystem.out.println("The Current list is:" + list);// We will delete sublist by using removeRange(int,int) // method of List.list.removeRange(2, 4);// New list Output after implementation of // removeRange(int,int) method.System.out.println("The New list is:" + list);} }

    Output

    輸出量

    E:\Programs>javac DeleteSublist.javaE:\Programs>java DeleteSublist The Current list is:[10, 20, 30, 40, 50] The New list is:[10, 20, 50]

    翻譯自: https://www.includehelp.com/java/how-to-remove-a-sublist-from-a-list-in-java.aspx

    java字符串刪掉子串

    總結(jié)

    以上是生活随笔為你收集整理的java字符串删掉子串_如何从Java中的列表中删除子列表?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。