Home > Software engineering >  can I Use parallel stream or is there any other way
can I Use parallel stream or is there any other way

Time:04-06

I want to ask how to write this below code in groovy Thanks alot;)

  List < String > nums = ['a','b']

  Map<String, Long> counts = nums.parallelStream()
  .collect( Collectors.groupingBy(k -> k.toLowerCase(), 
  Collectors.counting()) );          
              


Output in java: {a:1,b:1}

I tried using the same but it gives error below:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/home/cg/root/492337/main.groovy: 7: unexpected token: -> @ line 7, column 43.
lect( Collectors.groupingBy(k -\> k.toLow

CodePudding user response:

import java.util.stream.Collectors

List < String > nums = ['a','b']

Map<String, Long> counts = nums.parallelStream()
  .collect( Collectors.groupingBy( {k -> k.toLowerCase()}, Collectors.counting()) )
  • Related