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

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

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

String.getChars介绍

[英]Copies characters from this string into the destination character array.

The first character to be copied is at index srcBegin; the last character to be copied is at index srcEnd-1 (thus the total number of characters to be copied is srcEnd-srcBegin). The characters are copied into the subarray of dst starting at index dstBegin and ending at index:

dstbegin + (srcEnd-srcBegin) - 1

[中]将此字符串中的字符复制到目标字符数组中。
要复制的第一个字符位于索引srcBegin;要复制的最后一个字符位于索引srcEnd-1(因此要复制的字符总数为srcEnd-srcBegin)。将字符复制到dst的子数组中,从索引dstBegin开始,在索引处结束:

dstbegin + (srcEnd-srcBegin) - 1

代码示例

代码示例来源:origin: alibaba/druid

public final char[] sub_chars(int offset, int count) {
  char[] chars = new char[count];
  text.getChars(offset, offset + count, chars, 0);
  return chars;
}

代码示例来源:origin: alibaba/druid

public void arraycopy(int srcPos, char[] dest, int destPos, int length) {
  text.getChars(srcPos, srcPos + length, dest, destPos);
}

代码示例来源:origin: alibaba/druid

private static String subString(String src, int offset, int len) {
  char[] chars = new char[len];
  src.getChars(offset, offset + len, chars, 0);
  return new String(chars);
}

代码示例来源:origin: libgdx/libgdx

/** Constructs an instance that's initialized with the contents of the specified {@code String}. The capacity of the new
 * builder will be the length of the {@code String} plus 16.
 * 
 * @param string the {@code String} to copy into the builder.
 * @throws NullPointerException if {@code str} is {@code null}. */
public StringBuilder (String string) {
  length = string.length();
  chars = new char[length + INITIAL_CAPACITY];
  string.getChars(0, length, chars, 0);
}

代码示例来源:origin: libgdx/libgdx

/** Constructs an instance that's initialized with the contents of the specified {@code String}. The capacity of the new
 * builder will be the length of the {@code String} plus 16.
 * 
 * @param string the {@code String} to copy into the builder.
 * @throws NullPointerException if {@code str} is {@code null}. */
public StringBuilder (String string) {
  length = string.length();
  chars = new char[length + INITIAL_CAPACITY];
  string.getChars(0, length, chars, 0);
}

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

int reuseBuffMethod(final char[] reusable, final String data) {
  final int len = data.length();
  data.getChars(0, len, reusable, 0);
  for (int i = 0; i < len; i++) {
    if (reusable[i] <= ' ') {
      doThrow();
    }
  }
  return len;
}

代码示例来源:origin: prestodb/presto

private static int _outputSmallestL(char[] b, int off)
{
  int len = SMALLEST_LONG.length();
  SMALLEST_LONG.getChars(0, len, b, off);
  return (off + len);
}

代码示例来源:origin: prestodb/presto

@Override
public int appendUnquoted(char[] buffer, int offset) {
  String str = _value;
  final int length = str.length();
  if ((offset + length) > buffer.length) {
    return -1;
  }
  str.getChars(0,  length, buffer, offset);
  return length;
}

代码示例来源:origin: prestodb/presto

private static int _outputSmallestI(char[] b, int off)
{
  int len = SMALLEST_INT.length();
  SMALLEST_INT.getChars(0, len, b, off);
  return (off + len);
}

代码示例来源:origin: redisson/redisson

private static int _outputSmallestI(char[] b, int off)
{
  int len = SMALLEST_INT.length();
  SMALLEST_INT.getChars(0, len, b, off);
  return (off + len);
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public int read(char[] cs, int off, int len) throws IOException {
  ensureOpen();
  if ((off < 0) || (off > cs.length) || (len < 0) ||
      ((off + len) > cs.length) || ((off + len) < 0)) {
    throw new IndexOutOfBoundsException();
  }
  if (len == 0) {
    return 0;
  }
  if (mPosition >= mLimit) {
    return -1;
  }
  int n = Math.min(mLimit - mPosition, len);
  mString.getChars(mPosition, mPosition + n, cs, off);
  mPosition += n;
  return n;
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public int read(char[] cs, int off, int len) throws IOException {
  ensureOpen();
  if ((off < 0) || (off > cs.length) || (len < 0) ||
      ((off + len) > cs.length) || ((off + len) < 0)) {
    throw new IndexOutOfBoundsException();
  }
  if (len == 0) {
    return 0;
  }
  if (mPosition >= mLimit) {
    return -1;
  }
  int n = Math.min(mLimit - mPosition, len);
  mString.getChars(mPosition, mPosition + n, cs, off);
  mPosition += n;
  return n;
}

代码示例来源:origin: libgdx/libgdx

public final CharBuffer get (char[] dest, int off, int len) {
  int length = dest.length;
  if ((off < 0) || (len < 0) || (long)off + (long)len > length) {
    throw new IndexOutOfBoundsException();
  }
  if (len > remaining()) {
    throw new BufferUnderflowException();
  }
  int newPosition = position + len;
  sequence.toString().getChars(position, newPosition, dest, off);
  position = newPosition;
  return this;
}

代码示例来源:origin: libgdx/libgdx

public final CharBuffer get (char[] dest, int off, int len) {
  int length = dest.length;
  if ((off < 0) || (len < 0) || (long)off + (long)len > length) {
    throw new IndexOutOfBoundsException();
  }
  if (len > remaining()) {
    throw new BufferUnderflowException();
  }
  int newPosition = position + len;
  sequence.toString().getChars(position, newPosition, dest, off);
  position = newPosition;
  return this;
}

代码示例来源:origin: libgdx/libgdx

final void append0 (String string) {
  if (string == null) {
    appendNull();
    return;
  }
  int adding = string.length();
  int newSize = length + adding;
  if (newSize > chars.length) {
    enlargeBuffer(newSize);
  }
  string.getChars(0, adding, chars, length);
  length = newSize;
}

代码示例来源:origin: libgdx/libgdx

final void append0 (String string) {
  if (string == null) {
    appendNull();
    return;
  }
  int adding = string.length();
  int newSize = length + adding;
  if (newSize > chars.length) {
    enlargeBuffer(newSize);
  }
  string.getChars(0, adding, chars, length);
  length = newSize;
}

代码示例来源:origin: libgdx/libgdx

final void insert0 (int index, String string) {
  if (0 <= index && index <= length) {
    if (string == null) {
      string = "null";
    }
    int min = string.length();
    if (min != 0) {
      move(min, index);
      string.getChars(0, min, chars, index);
      length += min;
    }
  } else {
    throw new StringIndexOutOfBoundsException(index);
  }
}

代码示例来源:origin: prestodb/presto

@Override
public void writeRaw(String text) throws IOException {
  final int len = text.length();
  final char[] buf = _charBuffer;
  if (len <= buf.length) {
    text.getChars(0, len, buf, 0);
    writeRaw(buf, 0, len);
  } else {
    writeRaw(text, 0, len);
  }
}

代码示例来源:origin: libgdx/libgdx

final void insert0 (int index, String string) {
  if (0 <= index && index <= length) {
    if (string == null) {
      string = "null";
    }
    int min = string.length();
    if (min != 0) {
      move(min, index);
      string.getChars(0, min, chars, index);
      length += min;
    }
  } else {
    throw new StringIndexOutOfBoundsException(index);
  }
}

代码示例来源:origin: redisson/redisson

@Override
public void writeStringUTF(String str) throws IOException {
  final int strlen = str.length();
  writeFInt(strlen);
  ensureFree(strlen*2);
  char c[] = getCharBuf(strlen);
  str.getChars(0,strlen,c,0);
  buffout.setChar(pos,c,0,strlen);
  pos += strlen*2;
}

相关文章

微信公众号

最新文章

更多