最初のステップで、次のコードを実行します。
public class Demo {
public static void main(String[] args) {
String x = "x";
long start = System.currentTimeMillis();
for (int i = 0; i < 100000; i++)
{
x = x.concat("s");
// x+="k";
}
System.out.println(System.currentTimeMillis() - start);
}
}
アウト: 13579。
2 番目のステップで、次のコードを実行します。
public class Demo {
public static void main(String[] args) {
String x = "x";
long start = System.currentTimeMillis();
for (int i = 0; i < 100000; i++)
{
//x = x.concat("s");
x+="k";
}
System.out.println(System.currentTimeMillis() - start);
}
}
アウト: 27328.
2 つの質問があります。
- 私の銀行印と言えますか?
- (+) と concat() のタイムラインに大きな違いがあるのはなぜですか??? 13.5秒 VS 27秒 なんで?