这是输入和输出的SQL版本:
with tab1 as (
select 1 as id from dual union all
select 1 as id from dual union all
select 2 as id from dual union all
select 2 as id from dual union all
select 5 as id from dual
)
select id from tab1 group by id having count(id)=1;
Output is Id=5 and count is 1
Run Code Online (Sandbox Code Playgroud)
因为5不重复.我如何使用JAVA 8流实现它?
我试过下面,但很明显它给出了错误的结果
List<Integer> myList = new ArrayList<Integer>();
myList.add(1);
myList.add(1);
myList.add(2);
myList.add(2);
myList.add(5);
Long f = myList.stream()
.distinct().count();
System.out.println(f);
Run Code Online (Sandbox Code Playgroud)