From 194425d7875ef42fce52516ed59c81ee97720399 Mon Sep 17 00:00:00 2001 From: Shaojin Wen Date: Fri, 5 Jul 2024 12:50:09 +0000 Subject: [PATCH] 8335645: j.u.Formatter#trailingZeros improved with String repeat Reviewed-by: liach, jlu, naoto --- src/java.base/share/classes/java/util/Formatter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/java.base/share/classes/java/util/Formatter.java b/src/java.base/share/classes/java/util/Formatter.java index 41b9540001c..dfdb77cc6ac 100644 --- a/src/java.base/share/classes/java/util/Formatter.java +++ b/src/java.base/share/classes/java/util/Formatter.java @@ -4249,8 +4249,8 @@ public final class Formatter implements Closeable, Flushable { // Add trailing zeros private void trailingZeros(StringBuilder sb, int nzeros) { - for (int i = 0; i < nzeros; i++) { - sb.append('0'); + if (nzeros > 0) { + sb.repeat('0', nzeros); } }