O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The most important method that does all the work in this recipe is the getStudentCountByOccupation(). It does the following:

  1. Group the number of students by profession. This can be done in a single line of code using the power of the new streaming APIs (added as part of Java 8):
        Map<String, Long> occupationBreakUp = 
                    students.stream().collect(
          Collectors.groupingBy(
            classifier,
            Collectors.counting()
          )
        );
  1. Build data required for PieChart. The PieChart instance's data is ObservableList of PieChart.Data. We first make use of Map obtained in the preceding step to create ArrayList of PieChart.Data. Then, we use the FXCollections.observableList() API to obtain ObservableList<PieChart.Data> from List<PieChart.Data>:
 List<PieChart.Data> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required