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


Java StringBuilder.toString方法代码示例

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


在下文中一共展示了StringBuilder.toString方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: cd

import java.lang.StringBuilder; //导入方法依赖的package包/类
private void cd() throws IOException, JsonException {
    String dirname = sc.nextLine().trim().toLowerCase(); //for doing case-insensitive comparison
    if (dirname.equals("..")) {
        String[] parts = this.path.split("/");
        StringBuilder sb = new StringBuilder("/");
        for(int i = 1, up = parts.length-1; i < up; i++) {
            sb.append(parts[i]);
            sb.append("/");
        }
        this.path = sb.toString();
        return;
    }

    Files files = api.mounts().mount(this.mountId).files().list(this.path);
    for(File f : files.files) {
        if (f.type.equals("dir") && f.name.toLowerCase().equals(dirname)) {
            this.path = (this.path + "/" + f.name).replaceAll("/+", "/");
            return;
        }
    }
    System.out.println("No such directory");
}
 
开发者ID:koofr,项目名称:java-koofr,代码行数:23,代码来源:Main.java

示例8: getStringsUntil

import java.lang.StringBuilder; //导入方法依赖的package包/类
public static String getStringsUntil(String delimiter){

    Scanner sc = new Scanner(System.in);
    StringBuilder sb = new StringBuilder();
    String temp;

    while (true){

        temp = sc.nextLine();
        if (temp.equals(delimiter)){
            break;
        }
        sb.append(temp);
        sb.append("\n");
    }

    return sb.toString();
}
 
开发者ID:Qu4tro,项目名称:OOP,代码行数:19,代码来源:Ex07InsertAndRemove.java

示例9: paste

import java.lang.StringBuilder; //导入方法依赖的package包/类
void paste (String content, boolean fireChangeEvent) {
	if (content == null) return;
	StringBuilder buffer = new StringBuilder();
	int textLength = text.length();
	if (hasSelection) textLength -= Math.abs(cursor - selectionStart);
	BitmapFontData data = style.font.getData();
	for (int i = 0, n = content.length(); i < n; i++) {
		if (!withinMaxLength(textLength + buffer.length())) break;
		char c = content.charAt(i);
		if (!(writeEnters && (c == ENTER_ANDROID || c == ENTER_DESKTOP))) {
			if (c == '\r' || c == '\n') continue;
			if (onlyFontChars && !data.hasGlyph(c)) continue;
			if (filter != null && !filter.acceptChar(this, c)) continue;
		}
		buffer.append(c);
	}
	content = buffer.toString();

	if (hasSelection) cursor = delete(fireChangeEvent);
	if (fireChangeEvent)
		changeText(text, insert(cursor, content, text));
	else
		text = insert(cursor, content, text);
	updateDisplayText();
	cursor += content.length();
}
 
开发者ID:kotcrab,项目名称:vis-editor,代码行数:27,代码来源:VisTextField.java

示例10: tupleTestParamsReplace

import java.lang.StringBuilder; //导入方法依赖的package包/类
static String tupleTestParamsReplace(int i, Function<Integer,String> repFun) {
    StringBuilder sB = new StringBuilder();
    boolean isFirst = true;
    for (int j = 1; j <= i; j++) {
        if (isFirst) {
            isFirst = false;
        } else {
            sB.append(",");
        }
        String repStr = repFun.apply(j);
        if (repStr == null) {
            sB.append("\"" + ordinal(j) + "\"");
        } else {
            sB.append(repStr);
        }
    }
    return sB.toString();
}
 
开发者ID:GlenKPeterson,项目名称:Paguro,代码行数:19,代码来源:TupleGenerator.java

示例11: toString

import java.lang.StringBuilder; //导入方法依赖的package包/类
@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("ReplicatedGlobalMutableState");
    sb.append(", allocatedExtraTierBulks=").append(getAllocatedExtraTierBulks());
    sb.append(", firstFreeTierIndex=").append(getFirstFreeTierIndex());
    sb.append(", extraTiersInUse=").append(getExtraTiersInUse());
    sb.append(", segmentHeadersOffset=").append(getSegmentHeadersOffset());
    sb.append(", dataStoreSize=").append(getDataStoreSize());
    sb.append(", currentCleanupSegmentIndex=").append(getCurrentCleanupSegmentIndex());
    sb.append(", modificationIteratorsCount=").append(getModificationIteratorsCount());
    sb.append(", modificationIteratorInit=[");
    for (int index = 0; index < 128; index++) {
        sb.append(getModificationIteratorInitAt(index)).append(',').append(' ');
    }
    sb.setCharAt(sb.length() - 2, ']');
    sb.setLength(sb.length() - 1);
    sb.setCharAt(28, '{');
    sb.append(' ').append('}');
    return sb.toString();
}
 
开发者ID:OpenHFT,项目名称:Chronicle-Map,代码行数:22,代码来源:ReplicatedGlobalMutableState$$Native.java

示例12: toJSON

import java.lang.StringBuilder; //导入方法依赖的package包/类
public String toJSON()
{
	StringBuilder json = new StringBuilder();
	json.append("{");
	if(this.playerIsOpen)
	{
		json.append("\"isPlaying\":\"").append(this.player.isPlaying()).append("\",");
		json.append("\"isPaused\":\"").append(this.player.isPaused()).append("\",");
		json.append("\"movie\":\"").append(this.player.getPlayingFile().getName()).append("\"");
	} 
	else {
		json.append("\"isPlaying\":\"").append(false).append("\",");
		json.append("\"isPaused\":\"").append(false).append("\",");
		json.append("\"movie\":\"").append(false).append("\"");
	}
	json.append("}");

	return json.toString();
}
 
开发者ID:RyanDawkins,项目名称:glowing-spice,代码行数:20,代码来源:NowPlaying.java

示例13: makeGene

import java.lang.StringBuilder; //导入方法依赖的package包/类
/**  
 * Generates a single gene, a random String of 1s and 0s
 * @return String - a randomly generated gene
 */
private String makeGene() {

    // Stringbuilder builds gene, one chromosome (1 or 0) at a time
    StringBuilder gene = new StringBuilder(number_of_items);

    // Each chromosome
    char c;

    // Loop creating gene
    for(int i = 0; i < number_of_items; i++) {
        c = '0';
        double rnd = Math.random(); 
        // If random number is greater than 0.5, chromosome is '1'
        // If random number is less than 0.5, chromosome is '0'
        if(rnd > 0.5) {
            c = '1';
        }
        // Append chromosome to gene
        gene.append(c);
    }
    // Stringbuilder object to string; return
    return gene.toString();
}
 
开发者ID:mmmayo13,项目名称:knapsack-problem-ga-java,代码行数:28,代码来源:KnapsackProblem.java

示例14: getName

import java.lang.StringBuilder; //导入方法依赖的package包/类
public String getName() {
    StringBuilder name = new StringBuilder();

    // Age
    if (getAge()>=21){
        name.append("old");
    }else{
        name.append("young");
    }

    //Income
    if (isRich()){
        name.append(" rich");
    }

    //Sex
    if (getSex() == Sex.MALE){
        name.append(" man");
    }else{
         name.append(" woman");
    }

    return name.toString();
}
 
开发者ID:apache,项目名称:servicemix,代码行数:25,代码来源:Person.java

示例15: detailedMapToString

import java.lang.StringBuilder; //导入方法依赖的package包/类
public static String detailedMapToString(Map map) {
	StringBuilder sb = new StringBuilder();
	sb.append("{\n");
	for(Object key : map.keySet()) {
		sb.append("\t");
		sb.append(String.valueOf(key));
		sb.append(": (");
		Object value = map.get(key);
		sb.append((value==null)? "NULL":value.getClass().getName());
		sb.append(") ");
		sb.append((value==null)? "NULL":String.valueOf(value));
		sb.append("\n");
	}
	sb.append("}");
	return sb.toString();
}
 
开发者ID:Pardot,项目名称:Rhombus,代码行数:17,代码来源:StringUtil.java


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