I have a string say 1234567890
and I want to append the ,
character to positions in the String so that the string becomes 1,234,567,890
. How do I go about it?
If the string has only 4 character like 1234, I could do:
if (str.length() >= 4) {
str= str.substring(0, str.length()-3)+","+str.substring(str.length() - 3, str.length());
}
but how would I do it in case the string is 1234567890? Thanks.