本文整理了Java中java.lang.StringBuilder.substring()
方法的一些代码示例,展示了StringBuilder.substring()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringBuilder.substring()
方法的具体详情如下:
包路径:java.lang.StringBuilder
类名称:StringBuilder
方法名:substring
暂无
代码示例来源:origin: alibaba/fastjson
protected String getResult() {
return result.length() != 0 ? result.substring(1) : "";
}
}
代码示例来源:origin: skylot/jadx
private void removeFirstEmptyLine() {
int len = NL.length();
if (buf.substring(0, len).equals(NL)) {
buf.delete(0, len);
}
}
代码示例来源:origin: netty/netty
/**
* @param addr byte array of a MAC address.
* @return hex formatted MAC address.
*/
public static String formatAddress(byte[] addr) {
StringBuilder buf = new StringBuilder(24);
for (byte b: addr) {
buf.append(String.format("%02x:", b & 0xff));
}
return buf.substring(0, buf.length() - 1);
}
代码示例来源:origin: netty/netty
/**
* Creates a new ephemeral port based on the ID of the specified channel.
* Note that we prepend an upper-case character so that it never conflicts with
* the addresses created by a user, which are always lower-cased on construction time.
*/
LocalAddress(Channel channel) {
StringBuilder buf = new StringBuilder(16);
buf.append("local:E");
buf.append(Long.toHexString(channel.hashCode() & 0xFFFFFFFFL | 0x100000000L));
buf.setCharAt(7, ':');
id = buf.substring(6);
strVal = buf.toString();
}
代码示例来源:origin: redisson/redisson
/**
* @param addr byte array of a MAC address.
* @return hex formatted MAC address.
*/
public static String formatAddress(byte[] addr) {
StringBuilder buf = new StringBuilder(24);
for (byte b: addr) {
buf.append(String.format("%02x:", b & 0xff));
}
return buf.substring(0, buf.length() - 1);
}
代码示例来源:origin: commons-codec/commons-codec
private boolean regionMatch(final StringBuilder string, final int index, final String test) {
boolean matches = false;
if( index >= 0 &&
index + test.length() - 1 < string.length() ) {
final String substring = string.substring( index, index + test.length());
matches = substring.equals( test );
}
return matches;
}
代码示例来源:origin: bumptech/glide
private CodeBlock generateSeeMethodJavadocInternal(
TypeName nameOfClassContainingMethod, String methodName,
List<Object> safeParameterNames) {
StringBuilder javadocString = new StringBuilder("@see $T#$L(");
List<Object> javadocArgs = new ArrayList<>();
javadocArgs.add(nameOfClassContainingMethod);
javadocArgs.add(methodName);
for (Object param : safeParameterNames) {
javadocString.append("$T, ");
javadocArgs.add(param);
}
if (javadocArgs.size() > 2) {
javadocString = new StringBuilder(javadocString.substring(0, javadocString.length() - 2));
}
javadocString.append(")\n");
return CodeBlock.of(javadocString.toString(), javadocArgs.toArray(new Object[0]));
}
代码示例来源:origin: redisson/redisson
/**
* Creates a new ephemeral port based on the ID of the specified channel.
* Note that we prepend an upper-case character so that it never conflicts with
* the addresses created by a user, which are always lower-cased on construction time.
*/
LocalAddress(Channel channel) {
StringBuilder buf = new StringBuilder(16);
buf.append("local:E");
buf.append(Long.toHexString(channel.hashCode() & 0xFFFFFFFFL | 0x100000000L));
buf.setCharAt(7, ':');
id = buf.substring(6);
strVal = buf.toString();
}
代码示例来源:origin: org.mockito/mockito-core
/**
* Joins Strings with EOL character
*
* @param start the starting String
* @param linePrefix the prefix for each line to be joined
* @param lines collection to join
*/
public static String join(String start, String linePrefix, Collection<?> lines) {
if (lines.isEmpty()) {
return "";
}
StringBuilder out = new StringBuilder(start);
for (Object line : lines) {
out.append(linePrefix).append(line).append("\n");
}
return out.substring(0, out.length() - 1); //lose last EOL
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Append the query string of the current request to the target redirect URL.
* @param targetUrl the StringBuilder to append the properties to
* @param request the current request
* @since 4.1
*/
protected void appendCurrentQueryParams(StringBuilder targetUrl, HttpServletRequest request) {
String query = request.getQueryString();
if (StringUtils.hasText(query)) {
// Extract anchor fragment, if any.
String fragment = null;
int anchorIndex = targetUrl.indexOf("#");
if (anchorIndex > -1) {
fragment = targetUrl.substring(anchorIndex);
targetUrl.delete(anchorIndex, targetUrl.length());
}
if (targetUrl.toString().indexOf('?') < 0) {
targetUrl.append('?').append(query);
}
else {
targetUrl.append('&').append(query);
}
// Append anchor fragment, if any, to end of URL.
if (fragment != null) {
targetUrl.append(fragment);
}
}
}
代码示例来源:origin: bumptech/glide
private StringBuilder createNewOptionAndCall(boolean memoize,
MethodSpec.Builder methodSpecBuilder,
String start, List<ParameterSpec> specs) {
StringBuilder createNewOptionAndCall = new StringBuilder(start);
if (!specs.isEmpty()) {
methodSpecBuilder.addParameters(specs);
for (ParameterSpec parameter : specs) {
createNewOptionAndCall.append(parameter.name);
// use the Application Context to avoid memory leaks.
if (memoize && isAndroidContext(parameter)) {
createNewOptionAndCall.append(".getApplicationContext()");
}
createNewOptionAndCall.append(", ");
}
createNewOptionAndCall = new StringBuilder(
createNewOptionAndCall.substring(0, createNewOptionAndCall.length() - 2));
}
createNewOptionAndCall.append(")");
return createNewOptionAndCall;
}
代码示例来源:origin: stanfordnlp/CoreNLP
private static String mergeLeavesIntoCollocatedString(Tree[] trees) {
StringBuilder sb = new StringBuilder(160);
for (Tree t: trees) {
ArrayList<TaggedWord> sent = t.taggedYield();
for (TaggedWord aSent : sent) {
sb.append(aSent.word()).append('_');
}
}
return sb.substring(0,sb.length() -1);
}
代码示例来源:origin: apache/zookeeper
public String ackSetsToString(){
StringBuilder sb = new StringBuilder();
for (QuorumVerifierAcksetPair qvAckset : qvAcksetPairs) {
sb.append(qvAckset.getAckset().toString()).append(",");
}
return sb.substring(0, sb.length()-1);
}
代码示例来源:origin: stanfordnlp/CoreNLP
private static String mergeLeavesIntoCollocatedString(Tree t) {
StringBuilder sb = new StringBuilder(160);
ArrayList<TaggedWord> sent = t.taggedYield();
for (TaggedWord aSent : sent) {
sb.append(aSent.word()).append('_');
}
return sb.substring(0,sb.length() -1);
}
代码示例来源:origin: bazelbuild/bazel
private String layoutInspect() {
ThreadContext context = getRuntime().getCurrentContext();
StringBuilder sb = new StringBuilder();
for (Descriptors.FieldDescriptor fdef : descriptor.getFields()) {
sb.append(Utils.unescapeIdentifier(fdef.getName()));
sb.append(": ");
sb.append(getField(context, fdef).inspect());
sb.append(", ");
}
return sb.substring(0, sb.length() - 2);
}
代码示例来源:origin: netty/netty
private String newLongValue() {
StringBuilder buf = new StringBuilder(2 * data.length + 5);
int i = 0;
i = appendHexDumpField(buf, i, MACHINE_ID.length);
i = appendHexDumpField(buf, i, PROCESS_ID_LEN);
i = appendHexDumpField(buf, i, SEQUENCE_LEN);
i = appendHexDumpField(buf, i, TIMESTAMP_LEN);
i = appendHexDumpField(buf, i, RANDOM_LEN);
assert i == data.length;
return buf.substring(0, buf.length() - 1);
}
代码示例来源:origin: bumptech/glide
private static TypeSpec generate(List<TypeElement> libraryModules,
Class<? extends Annotation> annotation) {
AnnotationSpec.Builder annotationBuilder =
AnnotationSpec.builder(Index.class);
String value = getAnnotationValue(annotation);
for (TypeElement childModule : libraryModules) {
annotationBuilder.addMember(value, "$S", ClassName.get(childModule).toString());
}
StringBuilder indexerName = new StringBuilder(
INDEXER_NAME_PREFIX + annotation.getSimpleName() + "_");
for (TypeElement element : libraryModules) {
indexerName.append(element.getQualifiedName().toString().replace(".", "_"));
indexerName.append("_");
}
indexerName = new StringBuilder(indexerName.substring(0, indexerName.length() - 1));
return TypeSpec.classBuilder(indexerName.toString())
.addAnnotation(annotationBuilder.build())
.addModifiers(Modifier.PUBLIC)
.build();
}
代码示例来源:origin: redisson/redisson
private String newLongValue() {
StringBuilder buf = new StringBuilder(2 * data.length + 5);
int i = 0;
i = appendHexDumpField(buf, i, MACHINE_ID.length);
i = appendHexDumpField(buf, i, PROCESS_ID_LEN);
i = appendHexDumpField(buf, i, SEQUENCE_LEN);
i = appendHexDumpField(buf, i, TIMESTAMP_LEN);
i = appendHexDumpField(buf, i, RANDOM_LEN);
assert i == data.length;
return buf.substring(0, buf.length() - 1);
}
代码示例来源:origin: bumptech/glide
void run() throws IOException {
List<String> results = new ArrayList<>();
for (TestCase testCase : testCases) {
results.addAll(testCase.test(strategy));
}
if (results.isEmpty()) {
return;
}
StringBuilder failure = new StringBuilder("Failing Tests:\n");
for (String result : results) {
failure.append(result).append("\n");
}
fail(failure.substring(0, failure.length() - 1));
}
代码示例来源:origin: skylot/jadx
public CodeWriter startLineWithNum(int sourceLine) {
if (sourceLine == 0) {
startLine();
return this;
}
if (ADD_LINE_NUMBERS) {
newLine();
attachSourceLine(sourceLine);
String ln = "/* " + sourceLine + " */ ";
add(ln);
if (indentStr.length() > ln.length()) {
add(indentStr.substring(ln.length()));
}
} else {
startLine();
attachSourceLine(sourceLine);
}
return this;
}
内容来源于网络,如有侵权,请联系作者删除!