java.lang.Integer.getChars()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(3.3k)|赞(0)|评价(0)|浏览(267)

本文整理了Java中java.lang.Integer.getChars()方法的一些代码示例,展示了Integer.getChars()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Integer.getChars()方法的具体详情如下:
包路径:java.lang.Integer
类名称:Integer
方法名:getChars

Integer.getChars介绍

[英]Places characters representing the integer i into the character array buf. The characters are placed into the buffer backwards starting with the least significant digit at the specified index (exclusive), and working backwards from there. Will fail if i == Integer.MIN_VALUE
[中]将表示整数i的字符放入字符数组buf中。字符从指定索引(排他)的最低有效位开始向后放入缓冲区,并从那里向后工作。如果i==整数,则将失败。最小值

代码示例

代码示例来源:origin: stackoverflow.com

  1. public AbstractStringBuilder append(int i) {
  2. if (i == Integer.MIN_VALUE) {
  3. append("-2147483648");
  4. return this;
  5. }
  6. int appendedLength = (i < 0) ? Integer.stringSize(-i) + 1
  7. : Integer.stringSize(i);
  8. int spaceNeeded = count + appendedLength;
  9. ensureCapacityInternal(spaceNeeded);
  10. Integer.getChars(i, spaceNeeded, value);
  11. count = spaceNeeded;
  12. return this;
  13. }

代码示例来源:origin: jtulach/bck2brwsr

  1. /**
  2. * Returns a {@code String} object representing the
  3. * specified integer. The argument is converted to signed decimal
  4. * representation and returned as a string, exactly as if the
  5. * argument and radix 10 were given as arguments to the {@link
  6. * #toString(int, int)} method.
  7. *
  8. * @param i an integer to be converted.
  9. * @return a string representation of the argument in base&nbsp;10.
  10. */
  11. @JavaScriptBody(args = "i", body = "return i.toString();")
  12. public static String toString(int i) {
  13. if (i == Integer.MIN_VALUE)
  14. return "-2147483648";
  15. int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
  16. char[] buf = new char[size];
  17. getChars(i, size, buf);
  18. return new String(buf, 0, size);
  19. }

代码示例来源:origin: stackoverflow.com

  1. // from AbstractStringBuilder
  2. public AbstractStringBuilder append(int i) {
  3. if (i == Integer.MIN_VALUE) {
  4. append("-2147483648");
  5. return this;
  6. }
  7. int appendedLength = (i < 0) ? Integer.stringSize(-i) + 1
  8. : Integer.stringSize(i);
  9. int spaceNeeded = count + appendedLength;
  10. ensureCapacityInternal(spaceNeeded);
  11. Integer.getChars(i, spaceNeeded, value);
  12. count = spaceNeeded;
  13. return this;
  14. }

代码示例来源:origin: org.apidesign.bck2brwsr/emul.mini

  1. /**
  2. * Returns a {@code String} object representing the
  3. * specified integer. The argument is converted to signed decimal
  4. * representation and returned as a string, exactly as if the
  5. * argument and radix 10 were given as arguments to the {@link
  6. * #toString(int, int)} method.
  7. *
  8. * @param i an integer to be converted.
  9. * @return a string representation of the argument in base&nbsp;10.
  10. */
  11. @JavaScriptBody(args = "i", body = "return i.toString();")
  12. public static String toString(int i) {
  13. if (i == Integer.MIN_VALUE)
  14. return "-2147483648";
  15. int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
  16. char[] buf = new char[size];
  17. getChars(i, size, buf);
  18. return new String(buf, 0, size);
  19. }

代码示例来源:origin: stackoverflow.com

  1. 605 public AbstractStringBuilder append(int i) {
  2. 606 if (i == Integer.MIN_VALUE) {
  3. 607 append("-2147483648");
  4. 608 return this;
  5. 609 }
  6. 610 int appendedLength = (i < 0) ? Integer.stringSize(-i) + 1
  7. 611 : Integer.stringSize(i);
  8. 612 int spaceNeeded = count + appendedLength;
  9. 613 if (spaceNeeded > value.length)
  10. 614 expandCapacity(spaceNeeded);
  11. 615 Integer.getChars(i, spaceNeeded, value);
  12. 616 count = spaceNeeded;
  13. 617 return this;
  14. 618 }
  15. 110 void expandCapacity(int minimumCapacity) {
  16. 111 int newCapacity = (value.length + 1) * 2;
  17. 112 if (newCapacity < 0) {
  18. 113 newCapacity = Integer.MAX_VALUE;
  19. 114 } else if (minimumCapacity > newCapacity) {
  20. 115 newCapacity = minimumCapacity;
  21. 116 }
  22. 117 value = Arrays.copyOf(value, newCapacity);
  23. 118 }

相关文章