class Program
{
private static Random random = new Random((int)DateTime.Now.Ticks);
static void Main(string[] args)
{ Console.WriteLine("Be patient, generating data..."); List<string> list = new List<string>();
List<string> toRemove = new List<string>();
for (int x = 0; x < 1000000; x++)
{
string randString = RandomString(random.Next(100));
list.Add(randString);
if (random.Next(1000) == 0)
toRemove.Insert(0, randString);
} List<string> l1 = new List<string>(list);
List<string> l2 = new List<string>(list);
List<string> l3 = new List<string>(list);
List<string> l4 = new List<string>(list);
List<string> l5 = new List<string>(list); Console.WriteLine("Be patient, testing..."); Stopwatch sw1 = Stopwatch.StartNew();
l1.RemoveAll(toRemove.Contains);
sw1.Stop(); Stopwatch sw2 = Stopwatch.StartNew();
l2.RemoveAll(new HashSet<string>(toRemove).Contains);
sw2.Stop(); Stopwatch sw3 = Stopwatch.StartNew();
l3 = l3.Except(toRemove).ToList();
sw3.Stop(); Stopwatch sw4 = Stopwatch.StartNew();
l4 = l4.Except(new HashSet<string>(toRemove)).ToList();
sw4.Stop(); //Stopwatch sw5 = Stopwatch.StartNew();
//l5 = l5.RemoveAll((x)=>x[0]==);
//sw5.Stop(); Console.WriteLine("L1.Len = {0}, Time taken: {1}ms", l1.Count, sw1.Elapsed.TotalMilliseconds);
Console.WriteLine("L2.Len = {0}, Time taken: {1}ms", l1.Count, sw2.Elapsed.TotalMilliseconds);
Console.WriteLine("L3.Len = {0}, Time taken: {1}ms", l1.Count, sw3.Elapsed.TotalMilliseconds);
Console.WriteLine("L4.Len = {0}, Time taken: {1}ms", l1.Count, sw4.Elapsed.TotalMilliseconds); Console.ReadKey();
//
//authorsList.RemoveAll((x) => x.firstname == "Bob"); //authorsList = authorsList.Except(authors).ToList(); }
private static string RandomString(int size)
{
StringBuilder builder = new StringBuilder();
char ch;
for (int i = 0; i < size; i++)
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
builder.Append(ch);
} return builder.ToString();
}
}

  

备注:这是网上找的例子大致方案就是这几种,具体使用哪种看自己的实际需求

List集合删除方法的更多相关文章

  1. java集合类遍历删除方法测试以及使用场景记录

    package test0; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java. ...

  2. python之集合及其方法---整理集

    集合的定义: 由不同元素组成.一组无序排列的可hash值.集合中元素必须是不可变类型 集合的定义方式: 由大括号组成: 每个元素用逗号分隔: 元素书写不是key-value形式: 集合是由不同元素组成 ...

  3. java集合的方法及使用详解

    一.java集合的分类及相互之间的关系 Collection接口:向下提供了List和Set两个子接口 |------List接口:存储有序的,存储元素可以重复 |------ArrayList(主要 ...

  4. List集合的方法总结

    1. 添加方法 boolean add(E e): 向集合的末尾添加指定的元素 boolean addAll(Collection<? extends E> c): 向集合的末尾添加一个指 ...

  5. 关于.NET中迭代器的实现以及集合扩展方法的理解

    在C#中所有的数据结构类型都实现IEnumerable或IEnumerable<T>接口(实现迭代器模式),可以实现对集合遍历(集合元素顺序访问).换句话可以这么说,只要实现上面这两个接口 ...

  6. ztree获取当前选中节点子节点id集合的方法(转载)

    本文实例讲述了ztree获取当前选中节点子节点id集合的方法.分享给大家供大家参考.具体分析如下: 要求:获取当前选中节点的子节点id集合. 步骤: 1.获取当前节点 2.用ztree的方法trans ...

  7. Windows服务的手动添加和删除方法

    Windows服务的手动添加和删除方法 服务,是指执行指定系统功能的程序.例程或进程,以便支持其他程序,尤其是低层(接近硬件)程序.其实,服务就是一种特殊的应用程序,它从服务启动开始就一直处于运行状态 ...

  8. ecshop后台"云提醒未激活 点击激活" 补丁删除方法

    ecshop后台"云提醒未激活 点击激活" 补丁删除方法 ECSHOP教程/ ecshop教程网(www.ecshop119.com) 2015-01-15   ecshop后台提 ...

  9. 一个封装较好的删除方法(Delete)

    前台的引用 @Html.ActionLink(“删除字样”,“后台的删除方法”,new{绑定id},new{@style="样式"});方法,如何要独立使用的话,一般还要使用到相应 ...

随机推荐

  1. Django之contenttypes组件

    目录 一. 介绍 二. 应用场景 1. 表结构设计的演变 2. GenericForeignKey和GenericRelation 3. 测试 一. 介绍 Django包含一个contenttypes ...

  2. lua学习笔记4--XLua

    下载XLua:   https://github.com/tencent/xlua 项目中使用XLua只需将Plugins和XLua两个文件夹拷贝到U3D中即可XLua只是核心,用于实现Lua和C#交 ...

  3. 综合对比 Kafka、RabbitMQ、RocketMQ、ActiveMQ 四个分布式消息队列

    来源:http://t.cn/RVDWcfe 一.资料文档 Kafka:中.有kafka作者自己写的书,网上资料也有一些.rabbitmq:多.有一些不错的书,网上资料多.zeromq:少.没有专门写 ...

  4. SpringCloud简历模板

    项目三:智慧生鲜(SpringCloud) 开发周期:5个月项目介绍:该项目是一个基于微服分布式的生鲜电商网站,主要模块有前台:用户模块.商品模块.购物车模块.订单模块.支付模块.抢购模块.后台:权限 ...

  5. CodeForces 1251B --- Binary Palindromes

    [CodeForces 1251B --- Binary Palindromes] Description A palindrome is a string t which reads the sam ...

  6. boostrap table接收到后台返回的数据格式不一致的解决方法

    后台使用的分页插件是mybatis的PageHelper,返回数据格式如下: 而bootstrap table插件需要服务端返回的数据格式中含有"total"和"rows ...

  7. Mf175-用户注册功能-埋点敏捷方案

    在不了解埋点系统的情况下,花了五六个小时 帮一位PM朋友做的方案.记录下来.以备后续参考 Mf178-用户注册功能-埋点敏捷方案 版本号 时间 撰写人 描述 V1.0 20190515-10:50:0 ...

  8. LC 200 Number of Islands

    问题描述 Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is ...

  9. socket传送文件格式的问题

    在python3中socket传送文件只能传送‘bytes'类型,如下例子: import socket client = socket.socket()client.connect(("l ...

  10. wc、iconv命令

    一.wc:统计文件打印换行符,单词和字节数 语法:       wc [OPTION] ... [FILE] ...       wc [OPTION] ... --files0-from = F 描 ...