STRCON.LOOP

Using string concatenation in a loop wastes time and memory. Use StringBuffer instead.

Example 1

9     public String test1(int n, String x) {
10      String res = "";
11      for (int i = 0; i < n; i++) {
12        res+=x;
13      }
14      return res;
15    }
16    // fixed code
17    public String test2(int n, String x) {
18      StringBuffer res = new StringBuffer();
19      for (int i = 0; i < n; i++) {
20        res.append(x);
21      }
22      return res.toString();
23    }

STRCON.LOOP is reported for line 12: Using append for string 'res' in a loop