博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java字符串删掉子串_如何从Java中的列表中删除子列表?
阅读量:2532 次
发布时间:2019-05-11

本文共 3402 字,大约阅读时间需要 11 分钟。

java字符串删掉子串

从列表中删除子列表 (Removing SubList from a List)

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

假设我们列出了一些这样的元素,

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,

这可以通过两种方式完成:

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

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

  2. 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,

我们在List方法中传递两个参数,

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

    Sourcing_index是子列表起点的选择。

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

    Destinating_index是对子列表终点的选择。

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 Output System.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 DeleteSublistThe 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,

我们在List方法中传递两个参数,

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

    Sourcing_index是子列表起点的选择。

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

    Destinating_index是对子列表终点的选择。

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 Output System.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 DeleteSublistThe Current list is:[10, 20, 30, 40, 50]The New list is:[10, 20, 50]

翻译自:

java字符串删掉子串

转载地址:http://sytzd.baihongyu.com/

你可能感兴趣的文章
情感分析-英文电影评论
查看>>
王者荣耀游戏服务器架构的演进读后感
查看>>
关于ajax请求controller返回中文乱码的解决方法!
查看>>
Objective-C 和 Core Foundation 对象相互转换的内存管理总结
查看>>
IOS音频1:之采用四种方式播放音频文件(一)AudioToolbox AVFoundation OpenAL AUDIO QUEUE...
查看>>
Linux nmon 命令
查看>>
使用 urllib 构造请求对象
查看>>
sql server book
查看>>
长亭技术专栏 安全攻防技术分享
查看>>
sql server dba
查看>>
visualvm
查看>>
docker(4):coreos+docker+rancher真厉害
查看>>
设计模式之代理模式,学习笔记
查看>>
在Qsys中创建用户自定义IP
查看>>
【leetcode】Container With Most Water
查看>>
Python -- machine learning, neural network -- PyBrain 机器学习 神经网络
查看>>
一道dp题目
查看>>
mysql中间件研究(tddl atlas cobar sharding-jdbc)
查看>>
Cast-128 加密算法和 MyPassWord 的破解
查看>>
4.28下午 听力611
查看>>