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

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

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

String.subSequence介绍

[英]Returns a new character sequence that is a subsequence of this sequence.

An invocation of this method of the form

str.subSequence(begin, end)

behaves in exactly the same way as the invocation

str.substring(begin, end)

This method is defined so that the String class can implement the CharSequence interface.
[中]返回作为此序列的子序列的新字符序列。
此表单方法的调用

str.subSequence(begin, end)

的行为方式与调用的行为方式完全相同

str.substring(begin, end)

此方法的定义使String类可以实现CharSequence接口。

代码示例

代码示例来源:origin: org.assertj/assertj-core

@Override
public CharSequence subSequence(int start, int end) {
 return string.subSequence(start, end);
}

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

@Override
 public CharSequence subSequence(int start, int end) {
  return string.subSequence(start, end);
 }
}

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

@Override
public CharSequence subSequence(int start, int end) {
 return "foo".subSequence(start, end);
}

代码示例来源:origin: AsyncHttpClient/async-http-client

public static CharSequence filterOutBrotliFromAcceptEncoding(String acceptEncoding) {
  // we don't support Brotly ATM
  if (acceptEncoding.endsWith(BROTLY_ACCEPT_ENCODING_SUFFIX)) {
   return acceptEncoding.subSequence(0, acceptEncoding.length() - BROTLY_ACCEPT_ENCODING_SUFFIX.length());
  }
  return acceptEncoding;
 }
}

代码示例来源:origin: org.apache.commons/commons-lang3

@Override
public CharSequence subSequence(final int arg0, final int arg1) {
  return value.subSequence(arg0, arg1);
}

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

@Override
public CharSequence subSequence(int start, int end) {
  return toString().subSequence(start, end);
}

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

@Override
public CharSequence subSequence(int start, int end) {
  return toString().subSequence(start, end);
}

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

/**
 * Get LineColumn from string till index.
 * @param source Source string.
 * @param index An index into the string.
 * @return A position in the source representing what line and column that index appears on.
 */
private static LineColumn getLineColumnOfIndex(String source, int index) {
  final String precedingText = source.subSequence(0, index).toString();
  final String[] precedingLines = NEWLINE_PATTERN.split(precedingText);
  final String lastLine = precedingLines[precedingLines.length - 1];
  return new LineColumn(precedingLines.length, lastLine.length());
}

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

@Override
public CharSequence subSequence(int start, int end) {
 return s.subSequence(start, end);
}

代码示例来源:origin: google/error-prone

@Override
public CharSequence subSequence(int beginIndex, int endIndex) {
 return contents().subSequence(beginIndex, endIndex);
}

代码示例来源:origin: siacs/Conversations

@Override
public final CharSequence subSequence(int start, int end) {
  return toString().subSequence(start, end);
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Override
public CharSequence subSequence(final int start, final int end) {
  return seq.subSequence(start, end);
}

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

public static Object parseMockValue(String mock, Type[] returnTypes) throws Exception {
  Object value = null;
  if ("empty".equals(mock)) {
    value = ReflectUtils.getEmptyObject(returnTypes != null && returnTypes.length > 0 ? (Class<?>) returnTypes[0] : null);
  } else if ("null".equals(mock)) {
    value = null;
  } else if ("true".equals(mock)) {
    value = true;
  } else if ("false".equals(mock)) {
    value = false;
  } else if (mock.length() >= 2 && (mock.startsWith("\"") && mock.endsWith("\"")
      || mock.startsWith("\'") && mock.endsWith("\'"))) {
    value = mock.subSequence(1, mock.length() - 1);
  } else if (returnTypes != null && returnTypes.length > 0 && returnTypes[0] == String.class) {
    value = mock;
  } else if (StringUtils.isNumeric(mock)) {
    value = JSON.parse(mock);
  } else if (mock.startsWith("{")) {
    value = JSON.parseObject(mock, Map.class);
  } else if (mock.startsWith("[")) {
    value = JSON.parseObject(mock, List.class);
  } else {
    value = mock;
  }
  if (ArrayUtils.isNotEmpty(returnTypes)) {
    value = PojoUtils.realize(value, (Class<?>) returnTypes[0], returnTypes.length > 1 ? returnTypes[1] : null);
  }
  return value;
}

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

public static Object parseMockValue(String mock, Type[] returnTypes) throws Exception {
  Object value = null;
  if ("empty".equals(mock)) {
    value = ReflectUtils.getEmptyObject(returnTypes != null && returnTypes.length > 0 ? (Class<?>) returnTypes[0] : null);
  } else if ("null".equals(mock)) {
    value = null;
  } else if ("true".equals(mock)) {
    value = true;
  } else if ("false".equals(mock)) {
    value = false;
  } else if (mock.length() >= 2 && (mock.startsWith("\"") && mock.endsWith("\"")
      || mock.startsWith("\'") && mock.endsWith("\'"))) {
    value = mock.subSequence(1, mock.length() - 1);
  } else if (returnTypes != null && returnTypes.length > 0 && returnTypes[0] == String.class) {
    value = mock;
  } else if (StringUtils.isNumeric(mock)) {
    value = JSON.parse(mock);
  } else if (mock.startsWith("{")) {
    value = JSON.parseObject(mock, Map.class);
  } else if (mock.startsWith("[")) {
    value = JSON.parseObject(mock, List.class);
  } else {
    value = mock;
  }
  if (ArrayUtils.isNotEmpty(returnTypes)) {
    value = PojoUtils.realize(value, (Class<?>) returnTypes[0], returnTypes.length > 1 ? returnTypes[1] : null);
  }
  return value;
}

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

boolean isVersionOnedotSixOrHigher(String hgout) {
  String hgVersion = parseGitVersion(hgout);
  Float aFloat = NumberUtils.createFloat(hgVersion.subSequence(0, 3).toString());
  return aFloat >= 1.6;
}

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

boolean isVersionOnedotZeorOrHigher(String hgout) {
  String hgVersion = parseHgVersion(hgout);
  Float aFloat = NumberUtils.createFloat(hgVersion.subSequence(0, 3).toString());
  return aFloat >= 1;
}

代码示例来源:origin: SonarSource/sonarqube

private static void checkDbIdentifierCharacters(String identifier, String identifierDesc) {
  checkArgument(identifier.length() > 0, "Identifier must not be empty");
  checkArgument(
   LOWER_CASE_ASCII_LETTERS_CHAR_MATCHER.or(DIGIT_CHAR_MATCHER).or(anyOf("_")).matchesAllOf(identifier),
   "%s must be lower case and contain only alphanumeric chars or '_', got '%s'", identifierDesc, identifier);
  checkArgument(
   DIGIT_CHAR_MATCHER.or(UNDERSCORE_CHAR_MATCHER).matchesNoneOf(identifier.subSequence(0, 1)),
   "%s must not start by a number or '_', got '%s'", identifierDesc, identifier);
 }
}

代码示例来源:origin: commons-codec/commons-codec

@Test
  public void testSpeedCheck3() throws EncoderException {
    final BeiderMorseEncoder bmpm = this.createGenericApproxEncoder();
    final String phrase = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";

    for (int i = 1; i <= phrase.length(); i++) {
      bmpm.encode(phrase.subSequence(0, i));
    }
  }
}

代码示例来源:origin: commons-codec/commons-codec

@Test
public void testSpeedCheck2() throws EncoderException {
  final BeiderMorseEncoder bmpm = this.createGenericApproxEncoder();
  final String phrase = "ItstheendoftheworldasweknowitandIfeelfine";
  for (int i = 1; i <= phrase.length(); i++) {
    bmpm.encode(phrase.subSequence(0, i));
  }
}

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

@Test
public void givenInitializingWithAttributeSet_whenMaxLengthDefined_thenRestrictTextLengthToMaxLength() {
 int maxLength = anyInteger();
 AttributeSet attrs = Robolectric.buildAttributeSet()
   .addAttribute(android.R.attr.maxLength, maxLength + "")
   .build();
 EditText editText = new EditText(context, attrs);
 String excessiveInput = stringOfLength(maxLength * 2);
 editText.setText(excessiveInput);
 assertThat((CharSequence) editText.getText().toString()).isEqualTo(excessiveInput.subSequence(0, maxLength));
}

相关文章