java.lang.CharSequence.length()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(312)

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

CharSequence.length介绍

[英]Returns the number of characters in this sequence.
[中]返回此序列中的字符数。

代码示例

代码示例来源:origin: google/guava

@Override
 public int size() {
  return sequence.length();
 }
}

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

/**
 * Gets a CharSequence length or {@code 0} if the CharSequence is
 * {@code null}.
 *
 * @param cs
 *            a CharSequence or {@code null}
 * @return CharSequence length or {@code 0} if the CharSequence is
 *         {@code null}.
 */
public static int length(final CharSequence cs) {
  return cs == null ? 0 : cs.length();
}

代码示例来源:origin: google/guava

@Override
public int lastIndexIn(CharSequence sequence) {
 return sequence.length() - 1;
}

代码示例来源:origin: google/guava

@Override
public boolean matchesAllOf(CharSequence sequence) {
 return sequence.length() == 0;
}

代码示例来源:origin: google/guava

@Override
public long copyTo(Appendable appendable) throws IOException {
 appendable.append(seq);
 return seq.length();
}

代码示例来源:origin: google/guava

@Override
public String replaceFrom(CharSequence sequence, CharSequence replacement) {
 StringBuilder result = new StringBuilder(sequence.length() * replacement.length());
 for (int i = 0; i < sequence.length(); i++) {
  result.append(replacement);
 }
 return result.toString();
}

代码示例来源:origin: google/guava

@Override
public String collapseFrom(CharSequence sequence, char replacement) {
 return (sequence.length() == 0) ? "" : String.valueOf(replacement);
}

代码示例来源:origin: google/guava

@Override
public String replaceFrom(CharSequence sequence, char replacement) {
 char[] array = new char[sequence.length()];
 Arrays.fill(array, replacement);
 return new String(array);
}

代码示例来源:origin: spring-projects/spring-framework

private static boolean containsText(CharSequence str) {
  int strLen = str.length();
  for (int i = 0; i < strLen; i++) {
    if (!Character.isWhitespace(str.charAt(i))) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: google/guava

/**
 * True when a valid surrogate pair starts at the given {@code index} in the given {@code string}.
 * Out-of-range indexes return false.
 */
@VisibleForTesting
static boolean validSurrogatePairAt(CharSequence string, int index) {
 return index >= 0
   && index <= (string.length() - 2)
   && Character.isHighSurrogate(string.charAt(index))
   && Character.isLowSurrogate(string.charAt(index + 1));
}

代码示例来源:origin: google/guava

@Override
int decodeTo(byte[] target, CharSequence chars) throws DecodingException {
 StringBuilder stripped = new StringBuilder(chars.length());
 for (int i = 0; i < chars.length(); i++) {
  char c = chars.charAt(i);
  if (separator.indexOf(c) < 0) {
   stripped.append(c);
  }
 }
 return delegate.decodeTo(target, stripped);
}

代码示例来源:origin: google/guava

@Override
public boolean canDecode(CharSequence chars) {
 StringBuilder builder = new StringBuilder();
 for (int i = 0; i < chars.length(); i++) {
  char c = chars.charAt(i);
  if (separator.indexOf(c) < 0) {
   builder.append(c);
  }
 }
 return delegate.canDecode(builder);
}

代码示例来源:origin: google/guava

@Override
public int indexIn(CharSequence sequence, int start) {
 int length = sequence.length();
 checkPositionIndex(start, length);
 return -1;
}

代码示例来源:origin: google/guava

@Override
public HashCode hashUnencodedChars(CharSequence input) {
 int len = input.length();
 ByteBuffer buffer = ByteBuffer.allocate(len * 2).order(ByteOrder.LITTLE_ENDIAN);
 for (int i = 0; i < len; i++) {
  buffer.putChar(input.charAt(i));
 }
 return hashBytes(buffer.array());
}

代码示例来源:origin: google/guava

@Override
public Hasher putUnencodedChars(CharSequence charSequence) {
 for (int i = 0, len = charSequence.length(); i < len; i++) {
  putChar(charSequence.charAt(i));
 }
 return this;
}

代码示例来源:origin: google/guava

@Override
public Writer append(CharSequence csq, int start, int end) {
 checkPositionIndexes(start, end, csq.length());
 return this;
}

代码示例来源:origin: google/guava

@Override
public int indexIn(CharSequence sequence, int start) {
 int length = sequence.length();
 checkPositionIndex(start, length);
 return (start == length) ? -1 : start;
}

代码示例来源:origin: spring-projects/spring-framework

int calculateCapacity(CharSequence sequence, Charset charset) {
  float maxBytesPerChar = this.charsetToMaxBytesPerChar
      .computeIfAbsent(charset, cs -> cs.newEncoder().maxBytesPerChar());
  float maxBytesForSequence = sequence.length() * maxBytesPerChar;
  return (int) Math.ceil(maxBytesForSequence);
}

代码示例来源:origin: google/guava

@Override
 public boolean apply(CharSequence input) {
  return (input.length() > 0) && (input.charAt(0) == 'a');
 }
};

代码示例来源:origin: google/guava

@Override
public HashCode hashUnencodedChars(CharSequence input) {
 int len = input.length();
 return newHasher(len * 2).putUnencodedChars(input).hash();
}

相关文章