How to get words average length using Lambda Expression

后端 未结 3 1362
终归单人心
终归单人心 2021-01-04 17:24

I have a word list text file, I want to get min, max and average word lengths from that file.

I have a stream method:

public static Stream

        
3条回答
  •  Happy的楠姐
    2021-01-04 17:45

    Based on official documentation about reductions

    System.out.println(readWords(filename)
                    .mapToInt(String::length)
                    .average()
                    .getAsDouble()
    );
    

    Note that you can and probably should use method references like String::length

提交回复
热议问题