简体   繁体   English

使用 Stream 一起验证两个列表

[英]Validate two lists together using Stream

Wish to compare, two (object) lists for希望比较,两个(对象)列表

  1. Not null不为空
  2. Not empty不是空的
  3. Equal Size大小相等
  4. Nth Element Field values are same第 N 个元素字段值相同

Possible?可能的?

String A = "one,two,three|four,five,six|seven,eight,nine"
String B = "three,six,nine"

List L1 = List.of(A.split("\\|"));
List L2 = List.of(B.split(","));

Give object of List L1, if the third sub value of an element matches with element of the List L2.如果元素的第三个子值与列表 L2 的元素匹配,则给出列表 L1 的对象。

Note: This answered the question when it was:注意:这回答了以下问题:

Wish to compare, two (object) lists for 希望比较,两个(对象)列表
1. Not null 1.不为空
2. Not empty 2. 不为空
3. Equal Size 3. 大小相等
4. Nth Element Field values are same 4.第N个元素字段值相同
Possible? 可能的?

Since then, it was significantly changed...从那时起,它发生了重大变化......


Seems like you can go with Objects.equals(list1, list2);似乎您可以使用Objects.equals(list1, list2);

  1. When only one of the lists is null, it returns false.当只有一个列表为空时,它返回 false。

2./3. 2./3。 When the sizes are different, it will return false.当大小不同时,它将返回false。

  1. When the elements differ, it will also return false.当元素不同时,它也会返回false。

In any other case, it will return true.在任何其他情况下,它将返回 true。

Disclaimer: This works for the standard Lists in the Collections Framework.免责声明:这适用于集合框架中的标准列表。 There might be other implementations which implement equals() differently (and therefore behave differently when applied to Objects.equals() ).可能还有其他实现方式以不同方式实现equals() (因此在应用于Objects.equals()时表现不同)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM