当前位置: 首页>>代码示例>>Java>>正文


Java StringBuilder类代码示例

本文整理汇总了Java中java.lang.StringBuilder的典型用法代码示例。如果您正苦于以下问题:Java StringBuilder类的具体用法?Java StringBuilder怎么用?Java StringBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StringBuilder类属于java.lang包,在下文中一共展示了StringBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getContents

import java.lang.StringBuilder; //导入依赖的package包/类
static public String getContents(File aFile) {

        StringBuilder contents = new StringBuilder();

        try {
            BufferedReader input = new BufferedReader(new FileReader(aFile));
            try {
                String line = null;

                while ((line = input.readLine()) != null) {
                    contents.append(line);

                }
            }
            finally {
                input.close();
            }
        }
        catch (IOException ex) {

        }
        return contents.toString();
    }
 
开发者ID:moparisthebest,项目名称:MoparScape,代码行数:24,代码来源:Player.java

示例2: dumpSuggestionsInfoInternal

import java.lang.StringBuilder; //导入依赖的package包/类
private void dumpSuggestionsInfoInternal(
        final StringBuilder sb, final SuggestionsInfo si, final int length, final int offset) {
    // Returned suggestions are contained in SuggestionsInfo
    final int len = si.getSuggestionsCount();
    sb.append('\n');
    for (int j = 0; j < len; ++j) {
        if (j != 0) {
            sb.append(", ");
        }
        sb.append(si.getSuggestionAt(j));
    }
    sb.append(" (" + len + ")");
    if (length != NOT_A_LENGTH) {
        sb.append(" length = " + length + ", offset = " + offset);
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:17,代码来源:HelloSpellCheckerActivity.java

示例3: onGetSentenceSuggestions

import java.lang.StringBuilder; //导入依赖的package包/类
/**
 * Callback for {@link SpellCheckerSession#getSentenceSuggestions(TextInfo[], int)}
 * @param results an array of {@link SentenceSuggestionsInfo}s.
 * These results are suggestions for {@link TextInfo}s
 * queried by {@link SpellCheckerSession#getSentenceSuggestions(TextInfo[], int)}.
 */
@Override
public void onGetSentenceSuggestions(final SentenceSuggestionsInfo[] arg0) {
    if (!isSentenceSpellCheckSupported()) {
        Log.e(TAG, "Sentence spell check is not supported on this platform, "
                + "but accidentially called.");
        return;
    }
    Log.d(TAG, "onGetSentenceSuggestions");
    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < arg0.length; ++i) {
        final SentenceSuggestionsInfo ssi = arg0[i];
        for (int j = 0; j < ssi.getSuggestionsCount(); ++j) {
            dumpSuggestionsInfoInternal(
                    sb, ssi.getSuggestionsInfoAt(j), ssi.getOffsetAt(j), ssi.getLengthAt(j));
        }
    }
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mMainView.append(sb.toString());
        }
    });
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:30,代码来源:HelloSpellCheckerActivity.java

示例4: toString

import java.lang.StringBuilder; //导入依赖的package包/类
/** Методы Object */
@Override public String toString() { 
    StringBuilder result=new StringBuilder();
    for(int n=0; n<this.transitions.size(); n++) {
        result.append("#");
        result.append(this.stateNames.get(n));
        Set<F> markers=this.markers.get(n);
        if(!markers.isEmpty()) {
            boolean first=true;
            for(F marker: markers)
                if(first) {
                    first=false;
                    result.append(String.format(":%s", marker));
                } else result.append(String.format(" %s", marker));
        };
        result.append(":");
        for(Map.Entry<P,State> entry: this.transitions.get(n).entrySet()) {
            P symbol=entry.getKey();
            if(symbol!=null) result.append(String.format(" %s→%d", symbol, entry.getValue().getId()));
            else result.append(String.format(" ε→%d", entry.getValue().getId()));
        };
        result.append("\n");
    };
    return result.toString();
}
 
开发者ID:alepoydes,项目名称:writing-compiler-for-neophytes,代码行数:26,代码来源:DFA.java

示例5: handleWarningMessage

import java.lang.StringBuilder; //导入依赖的package包/类
@EventHandler
public void handleWarningMessage(WarningSendEvent event) {
    Violation violation = event.getParent().getViolation();

    if (WARNABLE_VIOLATIONS.contains(violation.getClass())) {
        StringBuilder message = new StringBuilder(ChatColor.RED.toString());
        if (violation.getClass() == DuplicateMessageViolation.class) {
            message.append("This message was not sent because you are sending the same message too fast.");
        } else {
            message.append("This message was not sent to ")
                   .append(violation.isForceNoSend() ? "any" : "some")
                   .append(" players because it contained potentially offensive content.");
        }

        event.setMessage(message.toString());
    } else {
        event.setMessage(null);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ChatModerator,代码行数:20,代码来源:ViolationPreWarningListener.java

示例6: prepareStatement

import java.lang.StringBuilder; //导入依赖的package包/类
private PreparedStatement prepareStatement() {
List<ColumnMetadata> partkeys = cluster.getMetadata().getKeyspace(keyspaceName).getTable(tableName).getPartitionKey();
StringBuilder sb = new StringBuilder();
sb.append("SELECT COUNT(*) FROM ");
sb.append(keyspaceName).append(".").append(tableName);
sb.append(" WHERE Token(");
sb.append(partkeys.get(0).getName());
for (int i = 1; i < partkeys.size(); i++)
    sb.append(", ").append(partkeys.get(i).getName());
sb.append(") > ? AND Token(");
sb.append(partkeys.get(0).getName());
for (int i = 1; i < partkeys.size(); i++)
    sb.append(",").append(partkeys.get(i).getName());
sb.append(") <= ?");

debugPrint("Query: " + sb.toString(), true, 2);

return session.prepare(sb.toString()).setConsistencyLevel(consistencyLevel);
   }
 
开发者ID:brianmhess,项目名称:cassandra-count,代码行数:20,代码来源:CqlCount.java

示例7: stringFromFile

import java.lang.StringBuilder; //导入依赖的package包/类
/**
  Create a string that contains a representation of the content of
  a file for testing.
  @exception Exception Oops.
  */
public static String
stringFromFile(InputStream is)
	 throws Exception
{
	InputStreamReader isr = new InputStreamReader(is);
	BufferedReader br =
		new BufferedReader(isr);
	StringBuilder sb = new StringBuilder();
	String l;
	while((l = br.readLine()) != null) {
		sb.append(l);
		sb.append("<CR>");
	}
	is.close();
	return sb.toString();
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:22,代码来源:DbFile.java

示例8: readNumber

import java.lang.StringBuilder; //导入依赖的package包/类
static private Object readNumber(PushbackReader r, char initch) {
	StringBuilder sb = new StringBuilder();
	sb.append(initch);

	for(; ;)
		{
		int ch = read1(r);
		if(ch == -1 || isWhitespace(ch) || isMacro(ch))
			{
			unread(r, ch);
			break;
			}
		sb.append((char) ch);
		}

	String s = sb.toString();
	Object n = matchNumber(s);
	if(n == null)
		throw new NumberFormatException("Invalid number: " + s);
	return n;
}
 
开发者ID:mrange,项目名称:fsharpadvent2016,代码行数:22,代码来源:LispReader.java

示例9: invoke

import java.lang.StringBuilder; //导入依赖的package包/类
public Object invoke(Object reader, Object doublequote, Object opts, Object pendingForms) {
	StringBuilder sb = new StringBuilder();
	Reader r = (Reader) reader;
	for(int ch = read1(r); ch != '"'; ch = read1(r))
		{
		if(ch == -1)
			throw Util.runtimeException("EOF while reading regex");
		sb.append( (char) ch );
		if(ch == '\\')	//escape
			{
			ch = read1(r);
			if(ch == -1)
				throw Util.runtimeException("EOF while reading regex");
			sb.append( (char) ch ) ;
			}
		}
	return Pattern.compile(sb.toString());
}
 
开发者ID:mrange,项目名称:fsharpadvent2016,代码行数:19,代码来源:LispReader.java

示例10: verifyStringPut

import java.lang.StringBuilder; //导入依赖的package包/类
private void verifyStringPut(AmazonS3 mock, String key, String content) throws Exception {
  ArgumentCaptor<PutObjectRequest> argument
    = ArgumentCaptor.forClass(PutObjectRequest.class);
  verify(mock)
    .putObject(argument.capture());

  PutObjectRequest req = argument.getValue();
  assertEquals(key, req.getKey());
  assertEquals(this.testBucket, req.getBucketName());

  InputStreamReader input = new InputStreamReader(req.getInputStream(), "UTF-8");
  StringBuilder sb = new StringBuilder(1024);
  final char[] buffer = new char[1024];
  try {
    for(int read = input.read(buffer, 0, buffer.length);
            read != -1;
            read = input.read(buffer, 0, buffer.length)) {
      sb.append(buffer, 0, read);
    }
  } catch (IOException ignore) { }

  assertEquals(content, sb.toString());
}
 
开发者ID:DeviantArt,项目名称:kafka-connect-s3,代码行数:24,代码来源:S3WriterTest.java

示例11: encode

import java.lang.StringBuilder; //导入依赖的package包/类
public String encode() {
  if (!encodedTags.isEmpty()) {
    StringBuilder sb = new StringBuilder(this.metricName);
    sb.append('[');
    String prefix = "";
    for (String encodedTag : encodedTags) {
      sb.append(prefix);
      sb.append(encodedTag);
      prefix = ",";
    }
    sb.append(']');
    return sb.toString();
  } else {
    return this.metricName;
  }
}
 
开发者ID:circonus-labs,项目名称:metrics-circonus,代码行数:17,代码来源:TaggedName.java

示例12: getSchemaQuery

import java.lang.StringBuilder; //导入依赖的package包/类
/**
* Reformats the query to insert a LIMIT 1 prior to a Time constraint
*/
private static String getSchemaQuery(final String query)
{
  String stmt = getSchemaCoreQuery(query);
  List<String> tokens = tokenize(stmt);
  StringBuilder newQuery = new StringBuilder();
  boolean addedLimit = false;
  for (int indx = 0; indx < tokens.size(); indx++) {
    if (tokens.get(indx).trim().equalsIgnoreCase("limit")) {
      newQuery.append("LIMIT 1 ");
      indx++;
      addedLimit = true;
    } else if (tokens.get(indx).trim().equalsIgnoreCase("start")) {
      if (!addedLimit) {
        newQuery.append("LIMIT 1 ");
        newQuery.append(tokens.get(indx));
        addedLimit = true;
      } else
        newQuery.append(tokens.get(indx));
    } else
      newQuery.append(tokens.get(indx));
  }
  return newQuery.toString();
}
 
开发者ID:ibm-security-intelligence,项目名称:jdbc-driver,代码行数:27,代码来源:SparkAQL.java

示例13: reduce

import java.lang.StringBuilder; //导入依赖的package包/类
public void reduce(WritableComparable key, Iterator values,
		OutputCollector output, Reporter reporter) throws IOException {
	int count = 0;
	StringBuilder builder = new StringBuilder();
	while(values.hasNext()) {
		count += 1;
		if(count > 10000)
			break;
		String data = ((Text)values.next()).toString();
		int index = data.indexOf(":");
		String movie_id = data.substring(0, index);
		if(movieTitles.containsKey(movie_id)) {
			builder.append(movieTitles.get(movie_id));
			builder.append("\t");
		}
	}
	output.collect(key, new Text(builder.toString()));
}
 
开发者ID:shubhambhindwal,项目名称:canopy-clustering,代码行数:19,代码来源:NetflixKMeansIterViewer.java

示例14: map

import java.lang.StringBuilder; //导入依赖的package包/类
public void map(WritableComparable key, Writable value,
                OutputCollector output, Reporter reporter) throws IOException {
  // Prepare the input data.
  String page = value.toString();

  System.out.println("Page:" + page);
  String title = this.GetTitle(page, reporter);
  if (title.length() > 0) {
    reporter.setStatus(title);
  } else {
    return;
  }

  ArrayList<String> outlinks = this.GetOutlinks(page);
  StringBuilder builder = new StringBuilder();
  for (String link : outlinks) {
    link = link.replace(" ", "_");
    builder.append(" ");
    builder.append(link);
  }
  output.collect(new Text(title), new Text(builder.toString()));
}
 
开发者ID:shubhambhindwal,项目名称:canopy-clustering,代码行数:23,代码来源:GraphBuilderMapper.java

示例15: main

import java.lang.StringBuilder; //导入依赖的package包/类
public static void main(String[] args)
   {

StringBuilder s = new StringBuilder("Hahaha");

// Notice: void run method are the same to both, but I overloaded it.
Thread t = new Thread(new threadAndRunnable(s)); // this calls void run method 
t.start();                                       // by the Interface Runnable

(new threadAndRunnable()).start(); // this calls a Thread by class Thread()

for(int i=0; i < 10; i++) // And it, only repetely shows a message 
       {
    System.out.println("tchau!");
    try{Thread.sleep(90);}catch(InterruptedException e){} 
       }

   }
 
开发者ID:jozadaquebatista,项目名称:JAVA-Overview,代码行数:19,代码来源:threadAndRunnable.java


注:本文中的java.lang.StringBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。