0

I get the following errors:

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("\t");
          ^
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("\t");
          ^
symbol:   method append(String)
location: variable sb of type StringBuilder

After trying to compile the following code:

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("\t");
      }

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

I'm sorry if this is a repeat question (I'm pretty sure it is) but a quick search didn't yield anything useful, for me anyways.

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.

1
  • 1
    That code works just fine for me. Commented May 23, 2012 at 16:53

3 Answers 3

2

There is absolutely nothing wrong with the code in your question.

The most likely explanation is that the code you're compiling isn't identical to the code that is in the question. For one thing, line numbers in the code and in the first two error messages don't agree with each other.

Sign up to request clarification or add additional context in comments.

1 Comment

to aix sorry about the line numbers not matching up I had more lines of code that I deleted. I'm using jgrasp (I know I'm a noob) I guess its about time I maned up and used a real ide. I will try eclipse or maybe netbeans. I figured there wasn't anything wrong with the code but it just wouldn't compile
2

Its Working perfectly fine, if you are using eclipse, try creating another this project again , sometimes eclipse do mess around...

I executed it as it is...and got the following output

firstName   middleName  lastName

Comments

0

use StringBuffer instead of StringBuilder. Even I got the same error but it was resolved when I used StringBuffer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.