list<T>集合中的Remove()、RemoveAt()、RemoveRange()、RemoveAll()的用法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
List<string> str = new List<string> { "aa","a1","a2","bb","cc","dd","ee","ff"};
//str.Remove("aa");//指定要删除的内容
//str.RemoveAt(1);//用下表来指定要删除的内容此示例中删除的是bb内容
//str.RemoveRange(0, 2);//删除指定长度的内容此实例会删除aa和bb
//str.RemoveAll(a => a.Contains("a"));//使用拉姆达表达式寻找包含a的内容
//然后将包含a的这一类文件全部删除. foreach (string item in str)//遍历显示要显示的内容
{
Console.WriteLine(item);
} Console.ReadLine();
}
}
}
要把这个删除放在最上面因为代码的执行时从上面往下的.
static void Main(string[] args)
{
List<string> str = new List<string> { "aa","a1","a2","bb","cc","dd","ee","ff"};
List<string> str1 = new List<string>();
str1.Add("mm"); //添加
//str.Add("66");//是将内容按照下标添加到最后一个.
//str.AddRange(str1);//将一个list集合中的内容添加到另一个指定要添加的集合的后面
str. foreach (string item in str)//遍历显示要显示的内容
{
Console.WriteLine(item);
} Console.ReadLine();
}
这个数插入希望可以帮到需要的你们
list<T>集合中的Remove()、RemoveAt()、RemoveRange()、RemoveAll()的用法的更多相关文章
- Day07_39_集合中的remove()方法 与 迭代器中的remove()方法
集合中的remove()方法 与 迭代器中的remove()方法 深入remove()方法 iterator 中的remove()方法 collection 中的remove(Object)方法 注意 ...
- Day07_38_集合中的remove()方法
集合中的remove()方法 remove() 移除集合中的一个指定对象 代码实例 package com.shige.Collection; import java.util.ArrayList; ...
- Iterator的remove方法可保证从源集合中安全地删除对象(转)
如果对正在被迭代的集合进行结构上的改变(即对该集合使用add.remove或clear方法),那么迭代器就不再合法(并且在其后使用该迭代器将会有ConcurrentModificationExcept ...
- 声明一个set集合,使用HashSet类,来保存十个字符串信息,然后通过这个集合,然后使用iterator()方法,得到一个迭代器,遍历所有的集合中所有的字符串;然后拿出所有的字符串拼接到一个StringBuffer对象中,然后输出它的长度和具体内容; 验证集合的remove()、size()、contains()、isEmpty()等
package com.lanxi.demo1_3; import java.util.HashSet; import java.util.Iterator; import java.util.Set ...
- list,set等集合遍历时,不能remove集合中的元素。需要new一个Object或者list,set,里面add需要删除的元素,等集合遍历完了进行remove(Object)或者removeAll(list/set)操作
list,set等集合遍历时,不能remove集合中的元素.需要new一个Object或者list,set,里面add需要删除的元素,等集合遍历完了进行remove(Object)或者removeAl ...
- Lambda 表达式遍历集合时用remove方法删除list集合中满足条件的元素问题
一:循环遍历list集合的四种方式 简单for循环 iterator循环 增加for循环 Lanbda表达式 二:四种遍历方式的用法示例 //简单for循环 List<SalaryAdjustm ...
- [Java基础] Java中List.remove报错UnsupportedOperationException
Java中List.remove(removeRange,clear类似) 报出 UnsupportedOperationException 的错误.原来该List是一个AbstractList,不支 ...
- Java集合中Map接口的使用方法
Map接口 Map提供了一种映射关系,其中的元素是以键值对(key-value)的形式存储的,能够实现根据key快速查找value: Map中的键值对以Entry类型的对象实例形式存在: 建(key值 ...
- Java集合中Set的常见问题及用法
在这里演示的案例是衔接Java集合中的List(点击查看)那篇博文的,本节我们学习的Set的用法. Set是Collection的一个重要的子接口,Set中的元素是无序排列的,并且元素不可以重复,被称 ...
随机推荐
- Oracle 查询历史数据(转帖)
回复误删除数据信息. 1.执行 alter table table_name enable row movement; 2.执行 FlashBack table table_name to times ...
- leetcode763
public class Solution { public IList<int> PartitionLabels(string S) { var dic = new Dictionary ...
- 使用API调用外部程序并监控程序状态
Public Type SHELLEXECUTEINFO cbSize As Long fMask As Long hwnd As Long lpVerb As String ...
- Nginx rewrite使用
转自: https://www.cnblogs.com/czlun/articles/7010604.html
- shutdown和close的区别
[shutdown和close的区别] 当所有的数据操作结束以后,你可以调用close()函数来释放该socket,从而停止在该socket上的任何数据操作:close(sockfd); 你也可以调用 ...
- Yosemite 给 iOS 录屏
[Yosemite 给 iOS 录屏] Mac 升级到Yosemite后,支持iOS屏幕录制.把Mac和iPhone用数据线相连.打开QuickTime Player,新建一个影片. 从摄像头源中选择 ...
- So you've been rejected, now what? On appeals in peer-reviewed publications(From Wiley Exchanges)
Getting rejected stinks. Wouldn’t it be great if we could appeal people’s decisions in life? Imagine ...
- 【hdu3507】Print Article 【斜率优化dp】
题意 https://cn.vjudge.net/problem/HDU-3507 分析 斜率优化的模板题 #include <cstdio> #include <cstring&g ...
- golang之math/rand随机数
简单的随机数生成,结合时间模块初始化种子 package main import ( "fmt" "math/rand" "time" ) ...
- AI ML DL
在经历了蛮荒的PC互联网时代,混战的移动互联网时代,到现今最火的人工智能时代. 大数据.云计算.机器学习的技术应用,已经使得IT从业者的门槛越来越高. 套用一句樊登读书会的宣传口号“keep lear ...