java-stream-一行中列出的long列表

KKl*_*ala 2 java java-8 long-integer java-stream

所以我知道我可以用两.stream行来做到这一点,但不确定我是否只能用一行来做到这一点.这就是我所拥有的:

List<Long> abcIds= abcController.findByUserIds(userIds)
      .stream()
      .map(Abc::getAbcId)
      .collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)

但我希望abcIds成为一个整数列表,因为稍后我会使用它的其他函数.我知道我可以写这样的另一行来将List of Long转换为整数列表:

List<Integer> abcIntIds= abcIds.stream()
           .map(Long::intValue)
           .collec?t(Collectors.toList(??));
Run Code Online (Sandbox Code Playgroud)

但有没有办法把它写得更优雅?

Eug*_*ene 6

为什么不map两次?

abcController.findByUserIds(userIds)
    .stream()
    .map(Abc::getAbcId)
    .map(Long::intValue)
    .collec?t(Collectors.toList(??));
Run Code Online (Sandbox Code Playgroud)