## 如何最快的生成"00001"字符串，长度可自定义

xingmu 发布于 2011/10/13 10:09

String.valueOf(Math.round(Math.pow(10, size)) + 1).substring(1);//size是长度

0
String.format();
+1
0

0

#### 引用来自“xing.mu”的答案

0

0

0
int size=10;
for (int j = 0; j < 5; j++) {
Long tLong = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
String.valueOf(Math.round(Math.pow(10, size)) + 1).substring(1);
}
System.out.println(System.currentTimeMillis() - tLong);
}
=======================
464
437
467
453
454
0

0

```public String m(int qty){

StringBuilder sb = new StringBuilder();

for(int i=0;i<qty;i++){

sb.append("0");
}

return sb.toString();

}```

0

```public String m(int qty){
String zero = "0000000000000000000000000000000000000000000000000";
return zero.subString(0,qty);
}```

0

#### 引用来自“恺哥”的答案

```public String m(int qty){
String zero = "0000000000000000000000000000000000000000000000000";
return zero.subString(0,qty);
}```

char[] zero={'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};

return new String(zero, 0, qty);