There are many ways to do this task, and the correct choice is one that makes sense to you. So, rather than just plopping some code down here that you may not understand, may I suggest:
Stop using this thread and post a new thread in the New to Java forum. In that thread, explain what you're trying to do, ant the problem and/or error(s) that you have encountered. Post the code that you are using, and surround it with [code] tags by using the Code button above the typing area.
That way people can help you correct the code that you have, and the results will make sense to you, and you'll learn in the process.