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

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.java
E:\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,

我们在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.java
E:\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字符串删掉子串

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541581.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

备份linux系统报错_Linux 系统如何快速入门?分享民工哥总结的经验

大家好,我是民工哥。认识或熟悉我的人都知道,是做运维出身的,所以,很多时候,有很多朋友喜欢问我一些有关运维的问题,比如:我应该如何入门Linux系统运维?Linux系统运维到底需要学哪些…

pe联想服务器装系统教程视频,演示联想电脑u盘重装系统xp教程

联想电脑U盘重装XP系统的方法很多朋友询问,其实现在很多电脑已经不支持XP系统的安装了,如果你的联想电脑是近几年购买的,还是安装win10系统比较保险。当然联想电脑安装系统过程中遇到问题也可以联系人工客服。联想电脑如何使用U盘重装系统XP呢…

TCP Socket 粘包

这两天看csdn有一些关于socket粘包,socket缓冲区设置的问题。发现自己不是非常清楚,所以查资料了解记录一下: 一两个简单概念长连接与短连接:1.长连接 Client方与Server方先建立通讯连接。连接建立后不断…

离散数学和组合数学什么关系_关系类型| 离散数学

离散数学和组合数学什么关系关系类型 (Types of Relation) There are many types of relation which is exist between the sets, 集合之间存在许多类型的关系, 1. Universal Relation 1.普遍关系 A relation r from set a to B is said to be universal if: R A…

springboot公共模块打包_解决SpringBoot多模块发布时99%的问题?

每天都会分享Java架构文章,喜欢的朋友关注我。ps:文末有彩蛋,惊喜等着你如果使用的是 SpringBoot 多模块的项目,在发布的时候可能遇到各种各样的问题。本文归纳了以下 8 个原则和发布时经常出现的 4 个问题的解决方案,…

tomcat7的数据库连接池tomcatjdbc的25个优势

tomcat的JDBC连接池org.apache.tomcat.jdbc.pool更换或替代吗Apache Commons DBCP连接池。为什么我们须要一个新的连接池?这里有几个原因: 1.DBCP 1.x是单线程的。为了成为线程安全的 共享锁整个池在短时间内在两个对象 分配和对象返回。注意,这并不适用 下议院DBCP 2.x。 2.D…

weakhashmap_Java WeakHashMap entrySet()方法与示例

weakhashmapWeakHashMap类entrySet()方法 (WeakHashMap Class entrySet() method) entrySet() method is available in java.util package. entrySet()方法在java.util包中可用。 entrySet() method is used to retrieve the mappings that exist in this map to be viewed in …

定义整型数组_C++数组的定义与初始化(学习笔记:第6章 01)

数组的定义与使用[1]数组是具有一定顺序关系的若干相同类型变量的集合体,组成数组的变量称为该数组的元素。数组的定义方括号里面列出的常量表达式是数组每一维的下标个数。数组的下标不管从哪一维它都是从0开始数的。例如:int a[10]; 表示a为整型数组&a…

我们正在经历一个应用疲惫时代?

在移动互联网时代到来之后,应用程序成为了智能手机必备,也正因为万千开发者的参与,才让移动终端充分发挥出了强大的能量,当然,这些开发者也不断创造着造富神话,一个小团队在几个月的努力之后可能就会成为亿…

Java LinkedHashMap values()方法与示例

LinkedHashMap类的values()方法 (LinkedHashMap Class values() method) values() method is available in java.util package. values()方法在java.util包中可用。 values() method is used to get all the values exist in this LinkedHashMap to be viewed in a Collection.…

语句拼接_第2课:一个周末学会R语言数据处理:表拆分和拼接

从一线收集了两百个文件,要整合到一起?总部一张全国两百个城市的汇总表,拆成两百个小文件?开什么玩笑,难道要复制粘贴到天荒地老。。。不用这么麻烦,一个循环,一个语句,实现快速表拆…

Anaconda配置多spyder多python环境

作者:桂。 时间:2017-04-17 22:02:37 链接:http://www.cnblogs.com/xingshansi/p/6725298.html 前言 最近在看《统计学习方法》,打算配合《机器学习实战》一起,可后者的代码是基于python2.6的: All the co…

pytorch自定义新层demo_从头学pytorch(十一):自定义层

自定义layer不含模型参数的layer含模型参数的layer核心都一样,自定义一个继承自nn.Module的类,在类的forward函数里实现该layer的计算,不同的是,带参数的layer需要用到nn.Parameter不含模型参数的layer直接继承nn.Moduleimport torchfrom torch import nnclass CenteredLayer(n…

java日历类add方法_Java日历computeTime()方法及示例

java日历类add方法日历类computeTime()方法 (Calendar Class computeTime() method) computeTime() method is available in java.util package. java.util包中提供了computeTime()方法 。 computeTime() method is for conversion of current field values to the ms(millisec…

C++——智能指针和RAII

该文章代码均在gitee中开源 C智能指针hpphttps://gitee.com/Ehundred/cpp-knowledge-points/tree/master/%E6%99%BA%E8%83%BD%E6%8C%87%E9%92%88​​​​​​​ 智能指针 传统指针的问题 在C自定义类型中,我们为了避免内存泄漏,会采用析构函数的方法释…

移除元素所有事件监听_DOM 事件模型或 DOM 事件机制

DOM 事件模型DOM 的事件操作(监听和触发),都定义在EventTarget接口。所有节点对象都部署了这个接口,其他一些需要事件通信的浏览器内置对象(比如,XMLHttpRequest、AudioNode、AudioContext)也部…

gettimezone_Java日历getTimeZone()方法与示例

gettimezone日历类的getTimeZone()方法 (Calendar Class getTimeZone() method) getTimeZone() method is available in java.util package. getTimeZone()方法在java.util包中可用。 getTimeZone() method is used to return this Calendar time zone. getTimeZone()方法用于返…

cass展点不在原位置_cass展点之步骤及方法

cass展点之步骤及方法cass展点是根据手工或坐标正反算软件自动计算的结果,利用cass软件将点号、坐标及其高程自动展示到图纸上的一种方法。其基本步骤和方法如下:一、将井下测点的点号、以及计算好的Y坐标、X坐标、及高程由sheet1复制并粘贴到sheet2上面…

Java BufferedWriter close()方法与示例

BufferedWriter类close()方法 (BufferedWriter Class close() method) close() method is available in java.io package. close()方法在java.io包中可用。 close() method is used to flushes the characters from the stream and later will close it by using close() metho…

ISCC2014-reverse

这是我做reverse的题解。在咱逆向之路上的mark一下,,水平有限,大牛见笑。题目及题解链接:http://pan.baidu.com/s/1gd3k2RL 宗女齐姜 果然是仅仅有50分的难度,OD直接找到了flag. 找到杀手 这题用OD做非常麻烦。我改用I…