美文网首页Java
Groovy string append

Groovy string append

作者: JaedenKil | 来源:发表于2022-01-27 11:07 被阅读0次
import groovy.time.TimeCategory

class StringAppend {
    static void main(String[] args) {

        Date time01 = new Date()
        String str01 = ""
        for (int i = 1; i <= 50000; i++) {
            str01 = str01 + "HelloWorld"
        }
        Date time02 = new Date()
        println(TimeCategory.minus(time02, time01))

        Date time03 = new Date()
        ArrayList arr = []
        for (int i = 1; i <= 50000; i++) {
            arr.add("HelloWorld")
        }
        String str02 = arr.join("")
        Date time04 = new Date()
        println(TimeCategory.minus(time04, time03))

        Date time05 = new Date()
        StringBuilder sb = new StringBuilder()
        for (int i = 1; i <= 50000; i++) {
            sb.append("HelloWorld")
        }
        String str03 = sb.toString()
        Date time06 = new Date()
        println(TimeCategory.minus(time06, time05))

    }
}
14.346 seconds
0.039 seconds
0.039 seconds
public static String join(Iterable self, String separator) {
  StringBuilder buffer = new StringBuilder();
  boolean first = true;
  if (separator == null) {
    separator = "";
  }
...
}
~~

相关文章

网友评论

    本文标题:Groovy string append

    本文链接:https://www.haomeiwen.com/subject/znxahrtx.html