我尝试使用lambda表达式根据其他列表中的值从列表中删除某个对象。这是我的代码:
List<Client> clientsList = GetSomeList();
SortableSearchableList<Client> clients = new SortableSearchableList<Client>(clientsList);
clients.ToList().RemoveAll(x=> lstPostalCodes.Any(c => c.City.PostalCode == x.PostalCode && c.SubId == x.SubId));
当我使用方法RemoveAll表示删除了一定数量的项目但实际上没有。
答案 0 :(得分:2)
您正在创建一个新列表,使用import java.util.regex.Pattern;
import java.util.regex.Matcher;
class String_Match4
{
public static void main(String args[])
{
String input = "user client-id=12345.host client-id=745896.some fix client-num=12564";
Pattern p1 = Pattern.compile("(client-id=)(\\d+)");
Matcher m1 = p1.matcher(input);
StringBuffer result = new StringBuffer();
System.out.println(result);
while (m1.find()) {
m1.appendReplacement(result, m1.group(1) + "***masked***");
}
m1.appendTail(result);
System.out.println(result);
}
}
中的项目填充它,然后您浏览新列表中的项目并删除符合您条件的项目,然后你在地板上放下那个新的清单,再也不用了。您不会将其存储在任何地方,或以任何方式将其存储在以后的代码中。
如果您希望更改clients
中的项目,则需要从该集合中删除项目,而不是创建新集合并从该新集合中删除项目。
答案 1 :(得分:0)
我这样解决了:
List<Client> clientsList = GetSomeList();
clientsLists.RemoveAll(x=> lstPostalCodes.Any(c => c.City.PostalCode == x.PostalCode && c.SubId == x.SubId));
SortableSearchableList<Client> clients = new SortableSearchableList<Client>(clientsList);
在创建SortableSearchableList