zoukankan      html  css  js  c++  java
  • java8-Integer

    快速求数字的长度.

    final static int [] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999,
                                          99999999, 999999999, Integer.MAX_VALUE };
    
        // Requires positive x
        static int stringSize(int x) {
            for (int i=0; ; i++)
                if (x <= sizeTable[i])
                    return i+1;
        }

    IntegerCache

        private static class IntegerCache {
            static final int low = -128;
            static final int high;
            static final Integer cache[];
    
            static {
                // high value may be configured by property
                int h = 127;
                String integerCacheHighPropValue =
                    sun.misc.VM.getSavedProperty("java.lang.Integer.IntegerCache.high");
                if (integerCacheHighPropValue != null) {
                    try {
                        int i = parseInt(integerCacheHighPropValue);
                        i = Math.max(i, 127);
                        // Maximum array size is Integer.MAX_VALUE
                        h = Math.min(i, Integer.MAX_VALUE - (-low) -1);
                    } catch( NumberFormatException nfe) {
                        // If the property cannot be parsed into an int, ignore it.
                    }
                }
                high = h;
    
                cache = new Integer[(high - low) + 1];
                int j = low;
                for(int k = 0; k < cache.length; k++)
                    cache[k] = new Integer(j++);
    
                // range [-128, 127] must be interned (JLS7 5.1.7)
                assert IntegerCache.high >= 127;
            }
    
            private IntegerCache() {}
        }

    可以通过如下来改变

    -Djava.lang.Integer.IntegerCache.high=<size>
    -XX:AutoBoxCacheMax=<size>
  • 相关阅读:
    [Luogu] P1886 滑动窗口
    [Luogu] P1195 口袋的天空
    [Luogu] P1331 海战
    [Luogu] P3952 时间复杂度
    运营活动如何防刷
    考研政治刷题小程序
    考研刷题小程序
    在线答题活动小程序
    知识竞答小程序v2.0
    知识竞答小程序
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/11189932.html
Copyright © 2011-2022 走看看