java.lang.StringBuilder.deleteCharAt()方法的使用及代码示例

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

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

StringBuilder.deleteCharAt介绍

[英]Deletes the character at the specified index. shifts any remaining characters to the left.
[中]删除指定索引处的字符。将所有剩余字符向左移动。

代码示例

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

public void removeTrailingSlash() {
  int index = this.path.length() - 1;
  if (this.path.charAt(index) == '/') {
    this.path.deleteCharAt(index);
  }
}

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

private static void convertRemainingAccentCharacters(final StringBuilder decomposed) {
  for (int i = 0; i < decomposed.length(); i++) {
    if (decomposed.charAt(i) == '\u0141') {
      decomposed.deleteCharAt(i);
      decomposed.insert(i, 'L');
    } else if (decomposed.charAt(i) == '\u0142') {
      decomposed.deleteCharAt(i);
      decomposed.insert(i, 'l');
    }
  }
}

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

/**
 * Trim all occurrences of the supplied leading character from the given {@code String}.
 * @param str the {@code String} to check
 * @param leadingCharacter the leading character to be trimmed
 * @return the trimmed {@code String}
 */
public static String trimLeadingCharacter(String str, char leadingCharacter) {
  if (!hasLength(str)) {
    return str;
  }
  StringBuilder sb = new StringBuilder(str);
  while (sb.length() > 0 && sb.charAt(0) == leadingCharacter) {
    sb.deleteCharAt(0);
  }
  return sb.toString();
}

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

/**
 * Trim leading whitespace from the given {@code String}.
 * @param str the {@code String} to check
 * @return the trimmed {@code String}
 * @see java.lang.Character#isWhitespace
 */
public static String trimLeadingWhitespace(String str) {
  if (!hasLength(str)) {
    return str;
  }
  StringBuilder sb = new StringBuilder(str);
  while (sb.length() > 0 && Character.isWhitespace(sb.charAt(0))) {
    sb.deleteCharAt(0);
  }
  return sb.toString();
}

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

/**
 * Trim all occurrences of the supplied trailing character from the given {@code String}.
 * @param str the {@code String} to check
 * @param trailingCharacter the trailing character to be trimmed
 * @return the trimmed {@code String}
 */
public static String trimTrailingCharacter(String str, char trailingCharacter) {
  if (!hasLength(str)) {
    return str;
  }
  StringBuilder sb = new StringBuilder(str);
  while (sb.length() > 0 && sb.charAt(sb.length() - 1) == trailingCharacter) {
    sb.deleteCharAt(sb.length() - 1);
  }
  return sb.toString();
}

代码示例来源:origin: hankcs/HanLP

@Override
  public String toString()
  {
    final StringBuilder sb = new StringBuilder();
    for (String value : this.value)
    {
      sb.append(value);
      sb.append('\t');
    }
    return sb.deleteCharAt(sb.length() - 1).toString();
  }
}

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

/**
 * Trim trailing whitespace from the given {@code String}.
 * @param str the {@code String} to check
 * @return the trimmed {@code String}
 * @see java.lang.Character#isWhitespace
 */
public static String trimTrailingWhitespace(String str) {
  if (!hasLength(str)) {
    return str;
  }
  StringBuilder sb = new StringBuilder(str);
  while (sb.length() > 0 && Character.isWhitespace(sb.charAt(sb.length() - 1))) {
    sb.deleteCharAt(sb.length() - 1);
  }
  return sb.toString();
}

代码示例来源:origin: hankcs/HanLP

@Override
public String toString()
{
  StringBuilder sb = new StringBuilder();
  for (Sentence sentence : sentenceList)
  {
    sb.append(sentence);
    sb.append(' ');
  }
  if (sb.length() > 0) sb.deleteCharAt(sb.length() - 1);
  return sb.toString();
}

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

@Override
public String toString()
{
  if (fields.isEmpty()) {
    return "()";
  }
  else {
    StringBuilder builder = new StringBuilder("(");
    for (Field f : fields) {
      builder.append(f).append(",");
    }
    builder.deleteCharAt(builder.length() - 1);
    return builder.append(')').toString();
  }
}

代码示例来源:origin: elasticjob/elastic-job-lite

private String buildSelect(final String tableName, final Collection<String> tableFields) {
  StringBuilder sqlBuilder = new StringBuilder();
  sqlBuilder.append("SELECT ");
  for (String each : tableFields) {
    sqlBuilder.append(each).append(",");
  }
  sqlBuilder.deleteCharAt(sqlBuilder.length() - 1);
  sqlBuilder.append(" FROM ").append(tableName);
  return sqlBuilder.toString();
}

代码示例来源:origin: apache/flink

private void deleteLeft() {
  if (cursorPos > 0) {
    currentInput.deleteCharAt(cursorPos - 1);
    cursorPos--;
  }
  // reset view
  resetMainPart();
}

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

/** Useful method to convert a map of key,value pairs to a String to be used as part of a GET or POST content.
 * @param parameters A Map<String, String> with the parameters to encode.
 * @return The String with the parameters encoded. */
public static String convertHttpParameters (Map<String, String> parameters) {
  Set<String> keySet = parameters.keySet();
  StringBuilder convertedParameters = new StringBuilder();
  for (String name : keySet) {
    convertedParameters.append(encode(name, defaultEncoding));
    convertedParameters.append(nameValueSeparator);
    convertedParameters.append(encode(parameters.get(name), defaultEncoding));
    convertedParameters.append(parameterSeparator);
  }
  if (convertedParameters.length() > 0) convertedParameters.deleteCharAt(convertedParameters.length() - 1);
  return convertedParameters.toString();
}

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

/** Useful method to convert a map of key,value pairs to a String to be used as part of a GET or POST content.
 * @param parameters A Map<String, String> with the parameters to encode.
 * @return The String with the parameters encoded. */
public static String convertHttpParameters (Map<String, String> parameters) {
  Set<String> keySet = parameters.keySet();
  StringBuilder convertedParameters = new StringBuilder();
  for (String name : keySet) {
    convertedParameters.append(encode(name, defaultEncoding));
    convertedParameters.append(nameValueSeparator);
    convertedParameters.append(encode(parameters.get(name), defaultEncoding));
    convertedParameters.append(parameterSeparator);
  }
  if (convertedParameters.length() > 0) convertedParameters.deleteCharAt(convertedParameters.length() - 1);
  return convertedParameters.toString();
}

代码示例来源:origin: weibocom/motan

public static String extractProtocols(String export) {
    Map<String, Integer> protocols = parseExport(export);
    StringBuilder sb = new StringBuilder(16);
    for (String p : protocols.keySet()) {
      sb.append(p).append(MotanConstants.COMMA_SEPARATOR);
    }
    if (sb.length() > 0) {
      sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();

  }
}

代码示例来源:origin: weibocom/motan

public static void encodeAttachments(MultivaluedMap<String, Object> headers, Map<String, String> attachments) {
  if (attachments == null || attachments.isEmpty())
    return;
  StringBuilder value = new StringBuilder();
  for (Map.Entry<String, String> entry : attachments.entrySet()) {
    value.append(StringTools.urlEncode(entry.getKey())).append("=")
        .append(StringTools.urlEncode(entry.getValue())).append(";");
  }
  if (value.length() > 1)
    value.deleteCharAt(value.length() - 1);
  headers.add(ATTACHMENT_HEADER, value.toString());
}

代码示例来源:origin: apache/storm

private void setConfigs(int[] nums, String config) throws IOException {
  StringBuilder sb = new StringBuilder();
  for (int num : nums) {
    sb.append(num);
    sb.append(',');
  }
  sb.deleteCharAt(sb.length() - 1);
  CgroupUtils.writeFileByLine(CgroupUtils.getDir(this.dir, config), sb.toString());
}

代码示例来源:origin: lets-blade/blade

public String parsePath(String path) {
  if (StringKit.isBlank(path)) return path;
  String[] pathModule = path.split("/");
  Arrays.stream(pathModule)
      .filter(row -> !row.isEmpty())
      .map(this::rowToPath)
      .forEach(this::join);
  pathBuilder.deleteCharAt(pathBuilder.length() - 1);
  return build(true);
}

代码示例来源:origin: lets-blade/blade

public String parsePath(String path) {
  if (StringKit.isBlank(path)) return path;
  String[] pathModule = path.split("/");
  Arrays.stream(pathModule)
      .filter(row -> !row.isEmpty())
      .map(this::rowToPath)
      .forEach(this::join);
  pathBuilder.deleteCharAt(pathBuilder.length() - 1);
  return build(true);
}

代码示例来源:origin: skylot/jadx

public String decode(String attrName, long value) {
    MAttr attr = attrMap.get(attrName);
    if (attr == null) {
      return null;
    }
    if (attr.getType() == MAttrType.ENUM) {
      return attr.getValues().get(value);
    } else if (attr.getType() == MAttrType.FLAG) {
      StringBuilder sb = new StringBuilder();
      for (Map.Entry<Long, String> entry : attr.getValues().entrySet()) {
        if (value == entry.getKey()) {
          sb = new StringBuilder(entry.getValue() + "|");
          break;
        } else if ((value & entry.getKey()) == entry.getKey()) {
          sb.append(entry.getValue()).append('|');
        }
      }
      if (sb.length() != 0) {
        return sb.deleteCharAt(sb.length() - 1).toString();
      }
    }
    return null;
  }
}

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

public void testCharactersOfIsView() {
 StringBuilder builder = new StringBuilder("abc");
 List<Character> chars = Lists.charactersOf(builder);
 assertEquals(asList('a', 'b', 'c'), chars);
 builder.append("def");
 assertEquals(asList('a', 'b', 'c', 'd', 'e', 'f'), chars);
 builder.deleteCharAt(5);
 assertEquals(asList('a', 'b', 'c', 'd', 'e'), chars);
}

相关文章