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

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

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

StringBuilder.toString介绍

[英]Returns the contents of this builder.
[中]返回此生成器的内容。

代码示例

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

@Override
 public String toString() {
  StringBuilder description = new StringBuilder("CharMatcher.anyOf(\"");
  for (char c : chars) {
   description.append(showCharacter(c));
  }
  description.append("\")");
  return description.toString();
 }
}

代码示例来源: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: square/okhttp

@Override public String toString() {
  StringBuilder result = new StringBuilder();
  result.append(protocol == Protocol.HTTP_1_0 ? "HTTP/1.0" : "HTTP/1.1");
  result.append(' ').append(code);
  if (message != null) {
   result.append(' ').append(message);
  }
  return result.toString();
 }
}

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

IllegalArgumentException multiples(boolean overflow) {
 StringBuilder sb =
   new StringBuilder().append("expected one element but was: <").append(element);
 for (Object o : extras) {
  sb.append(", ").append(o);
 }
 if (overflow) {
  sb.append(", ...");
 }
 sb.append('>');
 throw new IllegalArgumentException(sb.toString());
}

代码示例来源:origin: square/okhttp

private X500Principal buildSubject() {
 StringBuilder nameBuilder = new StringBuilder();
 if (cn != null) {
  nameBuilder.append("CN=").append(cn);
 } else {
  nameBuilder.append("CN=").append(UUID.randomUUID());
 }
 if (ou != null) {
  nameBuilder.append(", OU=").append(ou);
 }
 return new X500Principal(nameBuilder.toString());
}

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

private static String getValue(Part part) throws IOException {
  BufferedReader reader = new BufferedReader(new InputStreamReader(part.getInputStream(), "UTF-8"));
  StringBuilder value = new StringBuilder();
  char[] buffer = new char[1024];
  for (int length = 0; (length = reader.read(buffer)) > 0;) {
    value.append(buffer, 0, length);
  }
  return value.toString();
}

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

@Override
public String toString() {
 StringBuilder builder = new StringBuilder(size() * 5);
 builder.append('[').append(array[start]);
 for (int i = start + 1; i < end; i++) {
  builder.append(", ").append(array[i]);
 }
 return builder.append(']').toString();
}

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

@Override
public String toString() {
 StringBuilder builder = new StringBuilder(size() * 3);
 builder.append('[').append(array[start]);
 for (int i = start + 1; i < end; i++) {
  builder.append(", ").append(array[i]);
 }
 return builder.append(']').toString();
}

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

/**
 * Returns a string containing the string representation of each entry in {@code entries}, using
 * the previously configured separator and key-value separator.
 *
 * @since 11.0
 */
@Beta
public String join(Iterator<? extends Entry<?, ?>> entries) {
 return appendTo(new StringBuilder(), entries).toString();
}

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

/**
 * Reads all characters from a {@link Readable} object into a {@link String}. Does not close the
 * {@code Readable}.
 *
 * @param r the object to read from
 * @return a string containing all the characters
 * @throws IOException if an I/O error occurs
 */
public static String toString(Readable r) throws IOException {
 return toStringBuilder(r).toString();
}

代码示例来源:origin: square/okhttp

/**
 * Returns the RSA private key encoded in <a href="https://tools.ietf.org/html/rfc5208">PKCS
 * #8</a> <a href="https://tools.ietf.org/html/rfc7468">PEM format</a>.
 */
public String privateKeyPkcs8Pem() {
 StringBuilder result = new StringBuilder();
 result.append("-----BEGIN PRIVATE KEY-----\n");
 encodeBase64Lines(result, ByteString.of(keyPair.getPrivate().getEncoded()));
 result.append("-----END PRIVATE KEY-----\n");
 return result.toString();
}

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

private static String toString(Cut<?> lowerBound, Cut<?> upperBound) {
 StringBuilder sb = new StringBuilder(16);
 lowerBound.describeAsLowerBound(sb);
 sb.append("..");
 upperBound.describeAsUpperBound(sb);
 return sb.toString();
}

代码示例来源:origin: square/okhttp

@Override public String toString() {
 StringBuilder result = new StringBuilder();
 for (int i = 0, size = size(); i < size; i++) {
  result.append(name(i)).append(": ").append(value(i)).append("\n");
 }
 return result.toString();
}

代码示例来源:origin: square/retrofit

@Override public String toString() {
  if (typeArguments.length == 0) return typeToString(rawType);
  StringBuilder result = new StringBuilder(30 * (typeArguments.length + 1));
  result.append(typeToString(rawType));
  result.append("<").append(typeToString(typeArguments[0]));
  for (int i = 1; i < typeArguments.length; i++) {
   result.append(", ").append(typeToString(typeArguments[i]));
  }
  return result.append(">").toString();
 }
}

代码示例来源:origin: ReactiveX/RxJava

@Override
  public String apply(Object[] args) {
    StringBuilder b = new StringBuilder();
    for (Object o : args) {
      b.append(o);
    }
    return b.toString();
  }
}).subscribe(ts);

代码示例来源:origin: square/okhttp

public static Part createFormData(String name, @Nullable String filename, RequestBody body) {
 if (name == null) {
  throw new NullPointerException("name == null");
 }
 StringBuilder disposition = new StringBuilder("form-data; name=");
 appendQuotedString(disposition, name);
 if (filename != null) {
  disposition.append("; filename=");
  appendQuotedString(disposition, filename);
 }
 return create(Headers.of("Content-Disposition", disposition.toString()), body);
}

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

static String iterationOrder(Iterable<? extends Node> iterable) {
 StringBuilder builder = new StringBuilder();
 for (Node t : iterable) {
  builder.append(t.value);
 }
 StringBuilder forEachBuilder = new StringBuilder();
 iterable.forEach(t -> forEachBuilder.append(t.value));
 assertTrue(
   "Iterator content was " + builder + " but forEach content was " + forEachBuilder,
   builder.toString().contentEquals(forEachBuilder));
 return builder.toString();
}

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

public void testAppendMethods() throws IOException {
 StringBuilder builder = new StringBuilder();
 Writer writer = new AppendableWriter(builder);
 writer.append("Hello,");
 writer.append(' ');
 writer.append("The World Wide Web", 4, 9);
 writer.append("!");
 assertEquals("Hello, World!", builder.toString());
}

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

/**
 * Encodes the an integer as a string with given radix, then uses {@link Ints#tryParse(String,
 * int)} to parse the result. Asserts the result is the same as what we started with.
 */
private static void radixEncodeParseAndAssertEquals(Integer value, int radix) {
 assertEquals("Radix: " + radix, value, Ints.tryParse(Integer.toString(value, radix), radix));
}

代码示例来源:origin: ReactiveX/RxJava

static void checkSchedulerBadMethod(String baseClassName) throws Exception {
  File f = MaybeNo2Dot0Since.findSource(baseClassName);
  if (f == null) {
    return;
  }
  StringBuilder b = readFile(f);
  StringBuilder e = new StringBuilder();
  scanForBadMethod(b, "@SchedulerSupport", "Scheduler:", e, baseClassName);
  if (e.length() != 0) {
    System.out.println(e);
    fail(e.toString());
  }
}

相关文章