Java supports regular expressions very well. Using zero-width assertions, you can add thousands to integers in one sentence. The code copy is as follows: "1234567890".replaceAll("(?<=//d)(?=(?://d{3})+$)", ","); // => 1,234,567,890