English 中文(简体)
使用. append (Java) 字符串构建器发生错误
原标题:StringBuilder getting error using .append (Java)

我犯了以下错误:

nameCombine.java:18: error: cannot find symbol
sb.append(s);"
  ^

symbol:   method append(String)
location: variable sb of type StringBuilder
nameCombine.java:19: error: cannot find symbol
        sb.append("	");
          ^
symbol:   method append(String)
location: variable sb of type StringBuilder
StringBuilder.java:16: error: cannot find symbol
        sb.append(s);
          ^
symbol:   method append(String)
location: variable sb of type StringBuilder
StringBuilder.java:17: error: cannot find symbol
        sb.append("	");
          ^
symbol:   method append(String)
location: variable sb of type StringBuilder

在试图编纂以下代码之后:

import java.util.ArrayList;

public class nameCombine {
   public static void main(String[] args) {
      ArrayList<String> list = new ArrayList<String>();
      list.add("firstName");
      list.add("middleName");
      list.add("lastName");

      StringBuilder sb = new StringBuilder();

      for (String s : list) {
         sb.append(s);
         sb.append("	");
      }

      System.out.println(sb.toString());
   }
}

我很抱歉,如果这是一个重复的问题(我敢肯定这是),但快速搜索没有产生任何有用的结果,反正对我而言。

What im trying to do (if you can t already tell):
Combine an arrayList (firstName, middleName, lastName) into one new string. Any suggestions as to how I can do that in Java is appreciated.

问题回答

你的问题里面的代码绝对没有问题

最有可能的解释是,您正在汇编的代码与问题所在的代码不相同。 首先,代码中的行号与前两个错误信息不一致。

如果你使用日食, 尝试再创造另一个这个项目, 有时日蚀会乱搞...

我按原样执行的... 结果结果如下

firstName   middleName  lastName

使用 StringBuffer 而不是 StringBuilder 。 即使我也有同样的错误, 但当我使用 StringBuffer 时已经解决了 。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签