Comparing elements from one hashset to another

H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

farah uitte de volgende tekst op 04/02/2006 01:22 PM:
Roedy,

For the retainAll method, a list of fruits that had been entered
individually as strings were used. My code hoever uses info from files
that are read into the program. Im having trouble modifying my code to
work around this, can you help??

Not if you give no information. I mean, do you really plan on doing any
serious programming? It is very straightforward what happens in the
code we gave you. If you don't understand it, I see no point in even
trying to cope with file input.

H.
--
Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFEL8rNe+7xMGD3itQRArz6AJ9oRWho7xJ/0U/dlPyTkd1DaHHNdQCaAnbp
bdFFheFRscfzvGXlCMA9nUY=
=nGEb
-----END PGP SIGNATURE-----
 
R

Roedy Green

For the retainAll method, a list of fruits that had been entered
individually as strings were used. My code hoever uses info from files
that are read into the program. Im having trouble modifying my code to
work around this, can you help??

The only difference will be how you get the words from the files into
the HashSets.. How you do that depends on the format of the files.

Presuming they are simple text files with many words per line and
punctuation, you might use a StreamTokenizer,
http://mindprod.com/jgloss/streamtokenizer.html StringTokenizer
http://mindprod.com/jgloss/stringtokenizern or Regex
http://mindprod.com/jgloss/regex.html split that breaks the words
apart at space or punctuation. You then add each word to HashSet A or
B. If they are one per line, you can read them with a
BufferedReader.readLine and trim.

To read the file for regex, see
http://mindprod.com/applets/fileio.html


If there are duplicates WITHIN a file you will find out from the
boolean returned by HashSet.add.
 
R

Remon van Vliet

Just me or did you just ask the same question three times? Anyway, make a
unit test and check if it produces the expected results (which it will).

Remon van Vliet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top