Ad
  • Default User Avatar

    you're a genius brother

  • Custom User Avatar

    So much to learn and this kind of solutions just make me want to lear more

  • Custom User Avatar

    sorting is O(nlogn) and summaryStatistics is O(n) (i think), so sorting is a lot slower for larger arrays

  • Custom User Avatar

    I dont know if this is still relevant but: stream(numbers.split(" ")) - this part splits String to array of strings dividing each by " " - so you will have as an output String[] of numbers (in our case), and then this array will get converted to stream, .mapToInt(Integer::parseInt) maps every string element of stream - one by one - to int: you may write this as: mapToInt(str -> Integer.parseInt(str)). .summaryStatistics() converts to IntSummaryStatistics object which stores some values related to collection as: count, sum, max and min - it is asigned to stats (var works as an auto in c++ - joker that is evaluated based on return value of right side in this case is just IntSummaryStatistics). Then in return we call getMin and getMax which is self explanatory - it is casted to String because we are adding also " " which is indication that this should be treated as String.

  • Custom User Avatar

    I considered using it but in the end, sticked to sorting - does anyone know how summaryStatistics compares to sorting performance wise

  • Default User Avatar

    me neither, since 1.8 ...