美文网首页
System.arraycopy 数组copy要比 for循环快

System.arraycopy 数组copy要比 for循环快

作者: ElonYanJ | 来源:发表于2018-03-09 18:13 被阅读9次

'''
char[] rest = new char[1000000];
for (int a = 0; a < 1000000; a++) {
rest[a] = 'a';
}

    long start1 = System.currentTimeMillis();
    int lengthSubstract = rest.length;
    char[] nextRest = new char[lengthSubstract - 1];
    System.arraycopy(rest, 0, nextRest, 0, lengthSubstract - 1);
    long end1 = System.currentTimeMillis() - start1;
    Log.d("ddddssss", end1 + "");

    long start2 = System.currentTimeMillis();
    int lengthSubstract2 = rest.length - 1;
    char[] nextRest2 = new char[lengthSubstract2];
    for (int a = 0; a < lengthSubstract2; a++) {
        nextRest2[a] = rest[a];
    }
    long end2 = System.currentTimeMillis() - start2;
    Log.d("ddddssss", end2 + "");

'''

相关文章

网友评论

      本文标题:System.arraycopy 数组copy要比 for循环快

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