0
paramList = new ArrayList<String>();
paramList.add(line.split(","));

When I used this, it gives me the error:

cannot find symbol
symbol:   method add(java.lang.String[])
location: interface java.util.List<java.lang.String>

With this, I would get output in this manner: "abc" "bvc" "ebf" . Now can I use trim to get rid of " ". So that the output becomes: abc bvc ebf

Input: "AAH196","17:13:00","02:49:00",287,166.03,"Austin","TX","Virginia Beach","VA"

Output: AAH196 17:13:00 02:49:00 287 166.03 Austin TX Virginia Beach VA

I need to remove the " "around the words and , between the words. I want to store this output and then jdbc will parse this data into the tables of my database on mysql.

6
  • 7
    Once again, you are trying to learn the basics of the language by asking questions instead of just looking at a beginners book. There are a million free tutorials on the net, or books you can buy that will teach you these basics. You're not going to learn the syntax of the entire language through us. Commented Nov 6, 2010 at 4:40
  • this was an error taht i havn't seen so far. That's why i asked it.If you dont want to answer. dont do. but plz, i request you to talk in a good manner. Commented Nov 6, 2010 at 4:44
  • There are a lot of us who like to help beginners, and some who don't. I guess try putting beginner in your title. And that "syntax error" is what you need help with. That should help filter it down to only answers and posts you want. Good luck & happy learning... Commented Nov 6, 2010 at 4:52
  • You should really take a look at Java's documentation. A search for "arraylist" will give you this as the first result: download.oracle.com/javase/1.4.2/docs/api/java/util/… Commented Nov 6, 2010 at 5:02
  • @shilps: Just to be clear, if you actually sit down with your textbook, you can be done this within a few hours, instead of taking several days. You are not saving time by trying to take shortcuts. Just do your reading! Commented Nov 7, 2010 at 18:03

2 Answers 2

4

paramList.add() wants a String but line.split(",") returns String[]

The two are not equivalent.

Maybe you want something like:

paramList = Array.asList(line.split(","));

or

paramList = new ArrayList<String>();
for(String s : line.split(",")){
  paramList.add(s);
}

As for the added question, there are lots of ways to skin a cat.

If the words are ALWAYS surrounded by quotes then you can do something like:

paramList = new ArrayList<String>();
for(String s : line.split(",")){
  paramList.add(s.substring(1, s.length());
}

This will remove the first and last char from the String. Which will always be the quotes. If you need something more flexible (For instance this solution would ruin string that aren't surrounded by quotes) then you should read up on regex and java's Pattern class to see what suites your needs.

As for the solution that you provided, trim() will only remove surrounding whitespace.

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

2 Comments

I'm not quite sure what you're saying. Can you post the code in question? What is the input? Do you mean that 'line' holds that value? What is the output? The code that you posted doesn't include what you're talking about.
stackoverflow.com/questions/4120272/… - please help me in this question
0
import java.util.ArrayList;

class TestGenericArray {

    public static void main(String[] args) {
        String[] stringArray = {"Apple", "Banana", "Orange"};
        ArrayList<String[]> arrayList = new ArrayList<String[]>();
        arrayList.add(stringArray);
    }
}

2 Comments

so there is no need to use split and trim?
I think the OP wants an List of String, not a List of String arrays.

Your Answer

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