public class Test {
    public static void main(String args[])
    {
       String str="1232342302";
        System.out.println(str.substring(0,1)+","+str.substring(1,4)+","+str.substring(4,7)+","+str.substring(7,10));
    }
}

解决方案 »

  1.   

    jdk1.5String加了format方法,类似于C语言的printf方法。
    System.out.println(String.format("%1$,d", Integer.parseInt(preactualValuestr)));
      

  2.   

    public class Test {
    public String A(String preactualValuestr){
    StringBuffer preactualValuestr2 = new StringBuffer();
    StringBuffer sb = new StringBuffer();
    for (int i = preactualValuestr.length() - 1; i >= 0; i--) {
    preactualValuestr2.append(preactualValuestr.charAt(i));
    }
    int len = preactualValuestr.length() / 3;
    if (preactualValuestr.length() % 3 == 0) {
    for (int j = 1; j < len; j++) {
    String aa;
    if (j == 1) {
    aa = preactualValuestr2.substring(0, 3 * j);
    } else {
    aa = preactualValuestr2.substring(3 * (j - 1), 3 * j);
    }
    sb.append(aa).append(",");
    }
    } else {
    for (int j = 1; j <= len; j++) {
    String aa;
    if (j == 1) {
    aa = preactualValuestr2.substring(0, 3 * j);
    } else { aa = preactualValuestr2.substring(3 * (j - 1), 3 * j);
    }
    sb.append(aa).append(",");
    }
    sb.append(preactualValuestr2.substring(3*len, preactualValuestr.length()));
    }
    StringBuffer end = new StringBuffer();
    for (int i = sb.length() - 1; i >= 0; i--) {
    end.append(sb.charAt(i));
    }
    return end.toString();
    }
    public static void main(String[] args) {
    String preactualValuestr = "1232342302";
    Test t = new Test();
    System.out.println(t.A(preactualValuestr));
    }}
      

  3.   


       String preactualValuestr="1232342302"; 
       System.out.printf("%,d",Integer.parseInt(preactualValuestr));   
      

  4.   

    /**
     * 編輯逗號處理
     * 
     * @param value
     *            指定字符串
     * @return String
     */
    public static String editComma(String value) {
    value = String.format("%1$,d", Integer.parseInt(value));
    return value;
    }