当前位置:网站首页>List的stream中Long对象与long判等问题记录
List的stream中Long对象与long判等问题记录
2022-07-03 17:37:00 【漁陽】
在stream.filter中比较Long!=long的过程中的结果并没有真正过滤掉,具体现象如下:
long[] a = new long[]{7864, 284, 347, 7732, 8498};
Long bid = 123123l;
List<Long> il = new ArrayList<>();
il.add(1l);
il.add(2l);
il.add(3l);
il.add(123123l);
System.out.println(il.size());
List<Long> r=il.stream().filter(t -> t != bid).collect(Collectors.toList());
System.out.println(r.size());结果

从结果可以看出代码il.stream().filter(t -> t != bid).collect(Collectors.toList());中滤掉bid的值没有生效
问题分析:bid定义为对象,对象与具体值不能正常比较
解决办法:将bid改为big.longValue()

疑惑,Long对象直接比较是可以的,在stream中就不行了:
Long as = 1234l;
long b = 1234l;
long c = 11234l;
System.out.println(as != b);
System.out.println(as != c);结果

边栏推荐
- 问题随记 —— 在 edge 上看视频会绿屏
- Deops入门
- 2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)
- [combinatorics] recursive equation (special solution example 1 Hannover tower complete solution process | special solution example 2 special solution processing when the characteristic root is 1)
- Life is still confused? Maybe these subscription numbers have the answers you need!
- Enterprise custom form engine solution (XI) -- form rule engine 1
- TensorBoard快速入门(Pytorch使用TensorBoard)
- Cross border e-commerce: advantages of foreign trade enterprises in overseas social media marketing
- [error reporting] omp: error 15: initializing libiomp5md dll, but found libiomp5md. dll already initialized.
- 1147_ Makefile learning_ Target files and dependent files in makefile
猜你喜欢

How to purchase Google colab members in China

QT learning diary 9 - dialog box

互聯網醫院HIS管理平臺源碼,在線問診,預約掛號 智慧醫院小程序源碼

Golang unit test, mock test and benchmark test

Deops入门

Life is still confused? Maybe these subscription numbers have the answers you need!

kubernetes资源对象介绍及常用命令(四)

Golang单元测试、Mock测试以及基准测试

Kubernetes resource object introduction and common commands (III)

聊聊支付流程的设计与实现逻辑
随机推荐
Leetcode 538 converts binary search tree into cumulative tree -- recursive method and iterative method
[vscode] convert tabs to spaces
Create a new file from templates with bash script - create new file from templates with bash script
Test your trained model
How do large consumer enterprises make digital transformation?
Loop through JSON object list
[combinatorics] recursive equation (the problem of solving recursive equation with multiple roots | the problem is raised)
Kubernetes resource object introduction and common commands (4)
How SVN views modified file records
Detailed explanation of common network attacks
A day's work list of an ordinary programmer
Is AI too slow to design pictures and draw illustrations? 3 sets of practical brushes to save you
Wechat applet for the first time
Kubernetes resource object introduction and common commands (III)
Stm32h7 Hal library SPI DMA transmission has been in busy solution
Collection of the most beautiful graduation photos in the graduation season, collection of excellent graduation photos
SWM32系列教程4-端口映射及串口应用
Embedded-c language-7
Servlet specification Part II
Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)