Apache Commons StringUtils のように、整数を簡単にインクリメントし、ゼロで埋められた文字列として出力する既存のユーティリティはありますか?
のようなものを利用して自分で書くことは確かにできますString.format("%05d", counter)
が、これが既に利用可能なライブラリがあるかどうか疑問に思っています。
私は次のように使用できるものを想像しています:
// Create int counter with value of 0 padded to 4 digits
PaddedInt counter = new PaddedInt(0,4);
counter.incr();
// Print "0001"
System.out.println(counter);
// Print "0002"
System.out.println(counter.incr());
String text = "The counter is now "+counter.decr();
// Print "The counter is now 0001"
System.out.println(text);