String.repeat() method (available since Java 11). E.g.:
+
+ for(int i=0; i<count; i++) {
+ sb.append('*');
+ }
+
+Such code could be replaced with sb.append("*".repeat(count));
+
+
+ By default the inspection may wrap count expression with Math.max(0, count) if it cannot prove statically that count is
+ non-negative. This is done to prevent possible semantics change, as String.repeat() rejects negative numbers.
+ You may disable this behavior via option if you don't like it. Similarly a String to repeat could be wrapped with
+ String.valueOf to prevent possible NullPointerException if it's unknown whether it could be null.
+
New in 2019.1
+ +