当前位置:网站首页>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);结果

边栏推荐
- AcWing 4489. 最长子序列
- An example of HP array card troubleshooting
- PR second time
- RDS数据库的监测页面在哪看?
- University of Electronic Science and technology, accounting computerization, spring 20 final exam [standard answer]
- Website with JS doesn't work in IE9 until the Developer Tools is activated
- Leetcode 538 converts binary search tree into cumulative tree -- recursive method and iterative method
- [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
- Apache service suspended asynchronous acceptex failed
- 数学公式(测试)
猜你喜欢

Tensorboard quick start (pytoch uses tensorboard)

Baiwen.com 7 days Internet of things smart home learning experience punch in the next day

Internet Hospital his Management Platform source, online Inquiry, appointment Registration Smart Hospital Small program source

设计电商秒杀

Leetcode 669 pruning binary search tree -- recursive method and iterative method

POM in idea XML graying solution

面试官:值为 nil 为什么不等于 nil ?

TCP拥塞控制详解 | 3. 设计空间

Implementation of Tetris in C language

Great changes! National housing prices fell below the 10000 yuan mark
随机推荐
Embedded-c language-7
Financial management (Higher Vocational College) financial management online Assignment 1 in autumn 20
kubernetes资源对象介绍及常用命令(四)
数学公式(测试)
Online assignment 3 of mobile Internet technology in the 20th autumn of electronic technology [standard answer]
Type conversion, variable
QT learning diary 9 - dialog box
Draw some simple graphics with MFC
List of financial products in 2022
How SVN views modified file records
Comparison of kotlin collaboration + retro build network request schemes
i++与++i的区别:通俗易懂的讲述他们的区别
How do large consumer enterprises make digital transformation?
Stm32h7 Hal library SPI DMA transmission has been in busy solution
[combinatorics] recursive equation (general solution structure of recursive equation with multiple roots | linear independent solution | general solution with multiple roots | solution example of recu
Basic grammar of interview (Part 2)
1164 Good in C
互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
1146_ SiCp learning notes_ exponentiation
Qt调节Win屏幕亮度和声音大小