我是靠谱客的博主 直率百褶裙,这篇文章主要介绍Java基本类型int与类类型Integer性能差别,现在分享给大家,希望可以做个参考。

package com.hknaruto;

import java.util.Random;

/**
 * Created by yeqiang on 4/24/18.
 */
public class IntegerPerformanceTest {
    public static void main(String[] args) {
        long start, end;
        int rand = new Random().nextInt();
        start = System.nanoTime();
        int c = 0;
        for (Integer i = 0; i < 100000000; i++) {
            c += rand + i;
        }
        end = System.nanoTime();
        System.out.println(c);
        System.out.println(end - start);

        start = System.nanoTime();
        c = 0;
        for (int i = 0; i < 100000000; i++) {
            c += rand + i;
        }
        end = System.nanoTime();
        System.out.println(c);
        System.out.println(end - start);
    }
}

输出

-1508346240
396963018
-1508346240
34686095

最后

以上就是直率百褶裙最近收集整理的关于Java基本类型int与类类型Integer性能差别的全部内容,更多相关Java基本类型int与类类型Integer性能差别内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(122)

评论列表共有 0 条评论

立即
投稿
返回
顶部