本文整理汇总了Java中java.lang.StringBuilder.append方法的典型用法代码示例。如果您正苦于以下问题:Java StringBuilder.append方法的具体用法?Java StringBuilder.append怎么用?Java StringBuilder.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.append方法的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();
}
示例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);
}
}
示例3: 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();
}
示例4: 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);
}
}
示例5: 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);
}
示例6: 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;
}
示例7: 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());
}
示例8: 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();
}
示例9: 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()));
}
示例10: 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();
}
示例11: 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();
}
示例12: 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();
}
示例13: 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();
}
示例14: updateSelectedFileFieldText
import java.lang.StringBuilder; //导入方法依赖的package包/类
private void updateSelectedFileFieldText (boolean ignoreKeyboardFocus) {
if (ignoreKeyboardFocus == false && getChooserStage() != null) {
if (getChooserStage().getKeyboardFocus() == selectedFileTextField) return;
}
if (selectedItems.size == 0) {
selectedFileTextField.setText("");
} else if (selectedItems.size == 1) {
selectedFileTextField.setText(selectedItems.get(0).getFile().name());
} else {
StringBuilder builder = new StringBuilder();
for (FileItem item : selectedItems) {
builder.append('"');
builder.append(item.file.name());
builder.append("\" ");
}
selectedFileTextField.setText(builder.toString());
}
selectedFileTextField.setCursorAtTextEnd();
}
示例15: 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();
}