zoukankan      html  css  js  c++  java
  • 详解Integer.toString(int i)方法和String.valueOf(int i)方法

    通过查看String类的源码:

    public static String valueOf(int i) {
        return Integer.toString(i);
    }

    我们可以看到,String.valueOf(int i)其实是调用了Integer.toString(int i)方法的。

    再次通过查看Integer类的源码我们可以看到:

    public static String toString(int i) {
        if (i == Integer.MIN_VALUE)
            return "-2147483648";
        int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
        char[] buf = new char[size];
        getChars(i, size, buf);
        return new String(buf, true);
    }

    除了当参数i=-2^31时,值返回"-2147483648"外,当i=其他值时,都返回一个新的Stirng对象(new String(buf,true))。

  • 相关阅读:
    mysql资料
    MySQL启动与关闭
    poj 2778 DNA Sequence
    poj 1625 Censored!
    zoj 3228 Searching the String
    hdu 4605 Magic Ball Game
    hdu 4610 Cards
    SGU 439 A Secret Book
    NOI2013
    NOI2014
  • 原文地址:https://www.cnblogs.com/lxcmyf/p/6427972.html
Copyright © 2011-2022 走看看