1

How would I generate the output in Java with regex, split, or tokenizing? I need to remove the spaces around words and the commas between the words. I want to store this output and then jdbc will parse this data into the tables of my MySQL database.

2
  • I am thinking of using string[] because I have multiple rows of this kind of data.Which is one better? Commented Nov 6, 2010 at 2:55
  • @Adam: "The homework tag, like other so-called 'meta' tags, is now discouraged," but, shilps, please follow general guidelines, including stating specific restrictions, what you've tried so far, and what specifically is confusing you. Commented Nov 8, 2010 at 17:29

1 Answer 1

1

Since this is homework, I'm only going to give you HINTS. You then need to go away and try and code this yourself:

How would I generate the output

The simple way is to use String concatenation and System.out.println(...);

... if I have to do in java with Regex or split or tokenizer?

Either will work. Some ways are simpler than others. You figure out which. (It is important that you figure this out for yourself!)

I need to remove the " "around the words

If you need to do this after splitting, lookup String.trim().

... and , between the words.

You should already have done this with whatever it is you used to split the line into parts.

I want to store this output and then jdbc will parse this data into the tables of my database on mysql.

Do you need to do this? Does the homework question expect you to do this?

If you do, check your lecture notes / text book on how to use JDBC and SQL from Java. (I'm sure they won't have thrown you this question without giving you lots of material about this.)

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

1 Comment

thanks ..very appreciated. BTW, trim will remove the space , not " " and ,

Your Answer

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