当前位置:网站首页>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);
结果
边栏推荐
- Analyse ArrayList 3: suppression d'éléments
- Website with JS doesn't work in IE9 until the Developer Tools is activated
- Host based intrusion system IDS
- Stm32h7 Hal library SPI DMA transmission has been in busy solution
- [combinatorics] recursive equation (summary of the solution process of recursive equation | homogeneous | double root | non-homogeneous | characteristic root is 1 | exponential form | the bottom is th
- Test your trained model
- An example of HP array card troubleshooting
- STM32实现74HC595控制
- [combinatorics] recursive equation (the problem of solving recursive equation with multiple roots | the problem is raised)
- Write a program to process a list container of string type. Find a special value in the container 9.27: and delete it if found. Rewrite the above procedure with deque container.
猜你喜欢
2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)
Simple use of unity pen XR grab
Life is still confused? Maybe these subscription numbers have the answers you need!
[error reporting] omp: error 15: initializing libiomp5md dll, but found libiomp5md. dll already initialized.
Select 3 fcpx plug-ins. Come and see if you like them
Leetcode 538 converts binary search tree into cumulative tree -- recursive method and iterative method
Tensorboard quick start (pytoch uses tensorboard)
Leetcode 669 pruning binary search tree -- recursive method and iterative method
聊聊支付流程的设计与实现逻辑
vs2013已阻止安装程序,需安装IE10
随机推荐
Design e-commerce spike
[combinatorics] recursive equation (general solution structure of recursive equation with multiple roots | linear independent solution | general solution with multiple roots | solution example of recu
Internet hospital his management platform source code, online consultation, appointment registration smart hospital applet source code
Type conversion, variable
RDS数据库的监测页面在哪看?
2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)
Cloud primordial weekly | CNCF released the 2021 cloud primordial development status report, which was released on istio 1.13
Inheritance of ES6 class
ArrayList分析3 : 删除元素
【RT-Thread】nxp rt10xx 设备驱动框架之--rtc搭建和使用
UE4 official charging resources, with a total price of several thousand
MinGW compile boost library
How to purchase Google colab members in China
Financial management (Higher Vocational College) financial management online Assignment 1 in autumn 20
Stm32h7 Hal library SPI DMA transmission has been in busy solution
Qt调节Win屏幕亮度和声音大小
QT学习日记9——对话框
[error reporting] omp: error 15: initializing libiomp5md dll, but found libiomp5md. dll already initialized.
Interviewer: why is the value nil not equal to nil?
September, 19, "cam principle and application" online assignment [Full Score answer]