1. Learn
  2. /
  3. Courses
  4. /
  5. Optimizing Code in Java

Connected

Exercise

Optimizing a financial analysis application

As a Java developer for a financial analysis application, you've identified that one of your report-generation methods is creating excessive garbage and triggering frequent garbage collections. The report concatenates thousands of data points into a single string. You need to refactor this code to be more GC-friendly while maintaining the same functionality.

Instructions

100 XP
  • Create a new StringBuilder instance of the necessary length.
  • For every value in dataPoints, add the formatted value in the string builder.
  • Convert the StringBuilder to a String and return it.